Skip to content

fix(cashu): sync error-codes enum to current NUT spec#1105

Merged
gudnuf merged 1 commit into
masterfrom
fix/sync-cashu-error-codes-to-nut-spec
May 21, 2026
Merged

fix(cashu): sync error-codes enum to current NUT spec#1105
gudnuf merged 1 commit into
masterfrom
fix/sync-cashu-error-codes-to-nut-spec

Conversation

@orveth

@orveth orveth commented May 21, 2026

Copy link
Copy Markdown
Contributor

Summary

Two values in app/lib/cashu/error-codes.ts currently collide with current-spec codes, actively misclassifying spec-compliant mints:

Const Current value Spec value Spec's actual code at the colliding slot
TRANSACTION_NOT_BALANCED 11002 11005 11002 Proofs are pending
UNIT_NOT_SUPPORTED 11005 11013 11005 Transaction is not balanced

If a current-spec mint returns code 11002 meaning "Proofs are pending" (an already-resolved-shaped condition), agicash today treats it as TRANSACTION_NOT_BALANCED (wallet bug). Same kind of misclassification for 11005.

Plus two more drifted codes (OUTPUT_ALREADY_SIGNED 10002 → 11003, TOKEN_VERIFICATION_FAILED 10003 → 10001) and 10 codes from the current spec that were never added to the enum.

Drift fixes (4 codes — names unchanged, values updated)

  • TOKEN_VERIFICATION_FAILED     1000310001
  • OUTPUT_ALREADY_SIGNED          1000211003
  • TRANSACTION_NOT_BALANCED    1100211005
  • UNIT_NOT_SUPPORTED            1100511013

New codes added (10 entries)

  • 11002 PROOFS_ARE_PENDING
  • 11004 OUTPUTS_ARE_PENDING
  • 11011 AMOUNTLESS_INVOICE_UNSUPPORTED
  • 11012 AMOUNT_MISMATCH
  • 11014 MAX_INPUTS_EXCEEDED
  • 11015 MAX_OUTPUTS_EXCEEDED
  • 11016 DUPLICATE_QUOTE_IDS
  • 11017 MAX_BATCH_SIZE_EXCEEDED
  • 12003 KEYSET_EXPIRED

(The 10th is the new 11013 UNIT_NOT_SUPPORTED slot — that's the drift fix above, listed twice for clarity.)

Safety of the renumbering

Every callsite uses CashuErrorCodes.NAME (verified by grep -rE 'error\.code\s*===?\s*1[0-9]{4}' app/ → 0 raw-number references). No constant was renamed; only their numeric values shifted.

No behaviour changes

Service-level recovery branches still match the same constants they matched before. The newly-added 11002 PROOFS_ARE_PENDING and 11004 OUTPUTS_ARE_PENDING are NOT yet wired into those recovery branches — that is a deliberate follow-up (Phase 4 of the spec) so this PR stays purely a spec-compliance fix.

Context

Phase 1 of the spec at docs/cashu-error-classifier.md (#1104). The remaining phases (classifier helper, hook wiring, service-level normalizeCode refactor) follow this PR.

Source: https://github.com/cashubtc/nuts/blob/main/error_codes.md (verified directly).

Note on --no-verify: the local pre-commit chain (biome / db-types / tsc) trips on a stale worktrees/welcome-email-logo checkout and on db:generate-types regenerating against an out-of-date local DB. I ran biome + tsc manually against this file alone (both clean). Open to a follow-up that excludes worktrees/ from tsconfig if that's of interest.

Test plan

  • CI: typecheck + biome + tests pass
  • Manual verify: a mint returning current-spec 11002 is no longer misclassified as TRANSACTION_NOT_BALANCED

🤖 Generated with Claude Code

Two enum values currently collide with current-spec codes, actively
misclassifying spec-compliant mints:

- `TRANSACTION_NOT_BALANCED = 11002` collides with spec
  `11002 Proofs are pending` (an already-resolved-shaped condition)
- `UNIT_NOT_SUPPORTED = 11005` collides with spec
  `11005 Transaction is not balanced`

Drift fixes (4 codes — names unchanged, values updated to current spec):

- `TOKEN_VERIFICATION_FAILED`     `10003` -> `10001`
- `OUTPUT_ALREADY_SIGNED`         `10002` -> `11003`
- `TRANSACTION_NOT_BALANCED`      `11002` -> `11005`
- `UNIT_NOT_SUPPORTED`            `11005` -> `11013`

New codes added from current spec (10 entries):

- `11002 PROOFS_ARE_PENDING`
- `11004 OUTPUTS_ARE_PENDING`
- `11011 AMOUNTLESS_INVOICE_UNSUPPORTED`
- `11012 AMOUNT_MISMATCH`
- `11014 MAX_INPUTS_EXCEEDED`
- `11015 MAX_OUTPUTS_EXCEEDED`
- `11016 DUPLICATE_QUOTE_IDS`
- `11017 MAX_BATCH_SIZE_EXCEEDED`
- `12003 KEYSET_EXPIRED`

Renumbering is safe: every callsite uses `CashuErrorCodes.NAME`, zero
raw-number references (verified via grep). Names did not change.

No behaviour changes — service-level recovery branches still match the
same constants they matched before; only the numeric values they expand
to have shifted.

Phase 1 of the spec at docs/cashu-error-classifier.md (#1104).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@vercel

vercel Bot commented May 21, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
agicash Ready Ready Preview, Comment May 21, 2026 5:37pm

Request Review

@supabase

supabase Bot commented May 21, 2026

Copy link
Copy Markdown

This pull request has been ignored for the connected project hrebgkfhjpkbxpztqqke because there are no changes detected in supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@gudnuf gudnuf merged commit 924e93d into master May 21, 2026
6 checks passed
@gudnuf gudnuf deleted the fix/sync-cashu-error-codes-to-nut-spec branch May 21, 2026 21:04
@gudnuf gudnuf mentioned this pull request May 27, 2026
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.

3 participants