Skip to content

Add HasCallStack constraints to error call sites#1175

Draft
Jimbo4350 wants to merge 3 commits intomasterfrom
add-has-callstack-constraints
Draft

Add HasCallStack constraints to error call sites#1175
Jimbo4350 wants to merge 3 commits intomasterfrom
add-has-callstack-constraints

Conversation

@Jimbo4350
Copy link
Copy Markdown
Contributor

Changelog

- description: |
    Add HasCallStack constraints to functions containing error calls
    for better call stack traces when impossible-state violations occur.
    First step of ADR-011.
  type:
   - compatible
  projects:
   - cardano-api

Context

Implements the first step of ADR-011: Better call stacks of IO exceptions.

This PR adds HasCallStack constraints to ~30 functions across 19 files that contain error calls guarding logically impossible states (e.g. "Impossible! History should always be non-empty", Dijkstra era not-yet-supported guards). When these errors fire, the call stack trace will now be included in the error output, making debugging significantly easier.

This is the simple, low-risk approach: just threading HasCallStack through existing functions. It does not introduce the CIO/runIO/IoeWrapper machinery from the full ADR, which would disrupt the exception catching hierarchy.

Two error call sites were intentionally skipped because they are inside type class instance methods (ToJSON, HasTypeProxy) where the class definition doesn't support HasCallStack.

How to trust this PR

  • The change is purely additive — HasCallStack constraints only add call stack propagation, they don't change runtime behavior
  • All changes follow the existing pattern established in Cardano.Api.Error (throwErrorM, liftEitherError)
  • Library compiles cleanly with cabal build cardano-api:lib:cardano-api

Checklist

  • Commit sequence broadly makes sense and commits have useful messages
  • New tests are added if needed and existing tests are updated
  • Self-reviewed the diff

First step of ADR-011: add HasCallStack constraints to functions that
call error, so that impossible-state violations produce call stack
traces for easier debugging. This covers ~30 functions across 19 files
without introducing the IoeWrapper machinery.
…nctions

These functions either have temporary Dijkstra era placeholders (which
will be removed when Dijkstra is supported) or validation TODOs that
should be replaced with proper error handling rather than HasCallStack.
Dijkstra-era error placeholders don't need HasCallStack since the error
messages already identify the function. Fix error messages that were
missing the function name (fromShelleyMultiSig, fromAllegraTimelock,
getPlutusDatum, getAnchorDataFromCertificate).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant