docs(cashu): error-codes classifier + enum sync spec#1104
Closed
orveth wants to merge 1 commit into
Closed
Conversation
Spec for a minimal-change classifier that gives every cashu mint error code a single source of retry/recovery policy, plus a sync of the `error-codes.ts` enum to the current NUT spec. The enum sync is independently urgent: two enum values (`TRANSACTION_NOT_BALANCED = 11002`, `UNIT_NOT_SUPPORTED = 11005`) collide with current-spec codes (`11002 Proofs are pending`, `11005 Transaction is not balanced`) and actively misclassify spec-compliant mints. Subsumes the immediate fix in #1089 / PR #1090 and lays the foundation for #837 #421 #425 #673 #708. Implementation will follow in separate PRs; this PR carries the spec only. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
2 tasks
Contributor
|
superseeded by #1118 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Spec doc for a minimal-change classifier that gives every cashu mint error code a single source of retry/recovery policy, plus a sync of
app/lib/cashu/error-codes.tsto the current NUT spec.Draft because this PR carries the spec only. Implementation will follow in separate PRs once the design is reviewed here.
Why
Today, mint-error handling is scattered: each mutation has its own `instanceof MintOperationError` retry-skip, service-level recovery branches inline a legacy-code + Nutshell-message-string check, and many mutations have `throwOnError: true` that crashes the React boundary on transient mint blips. There's also a cluster of open bugs (#1089 / PR #1090, #837, #421, #425, #673, #708) all touching the same gap.
The proposal: one shared `classify(err)` returning `'transient' | 'permanent' | 'already-resolved' | 'unhandled'`, plus a `normalizeCode(err)` helper that centralises legacy-value + Nutshell pre-0.16.5 message-string fallback in one place. Strictly request-level — services keep their flow-specific recovery logic.
Critical finding from the spec sync work
The current `error-codes.ts` enum has two active collisions with the current NUT spec (https://github.com/cashubtc/nuts/blob/main/error_codes.md):
If a spec-compliant mint returns `11002` meaning "proofs pending" (an already-resolved-shaped condition), agicash currently treats it as `TRANSACTION_NOT_BALANCED` (wallet bug). Same shape for `11005`.
Plus two more drifted codes (`OUTPUT_ALREADY_SIGNED 10002→11003`, `TOKEN_VERIFICATION_FAILED 10003→10001`) and 10 missing codes (notably `11002 PROOFS_ARE_PENDING` and `11004 OUTPUTS_ARE_PENDING` which deserve already-resolved handling).
Renumbering is safe — every callsite uses `CashuErrorCodes.NAME`, zero raw-number references (verified via grep).
Scope (in)
Scope (out — explicit follow-ups)
Relation to PR #1090 / issue #1089
PR #1090 wraps `MintOperationError → DomainError(error.message)` at the service boundary as an immediate fix for #1089. The classifier subsumes it — `DomainError` always classifies as `permanent`, and `MintOperationError` with any code (including custom `20739`) also defaults to `permanent`. Recommendation: revert the PR #1090 wrap commit and use the classifier instead.
Estimated implementation diff
Total: ~350 LOC, single follow-up PR, no breaking changes.
Open implementation questions
Test plan
This PR adds only a docs file — no code or runtime changes.
🤖 Generated with Claude Code