Skip to content

fix(webapp): map custom program errors per failing program#158

Merged
dev-jodee merged 1 commit into
mainfrom
fix/transfer-missing-delegatee-token-account
Jun 4, 2026
Merged

fix(webapp): map custom program errors per failing program#158
dev-jodee merged 1 commit into
mainfrom
fix/transfer-missing-delegatee-token-account

Conversation

@dev-jodee
Copy link
Copy Markdown
Collaborator

@dev-jodee dev-jodee commented Jun 4, 2026

Summary

  • parseProgramError applied the SPL Token error table to any unmapped custom error code, regardless of which program threw it. An error 17 from a non-token program would be mislabeled as "Token account is frozen".
  • Now attributes the custom error code to the failing program before mapping: our subscriptions program (from the IDL publicKey) vs SPL Token / Token-2022 (TOKEN_PROGRAM_ADDRESS / TOKEN_2022_PROGRAM_ADDRESS). Unattributable codes fall back to naming the program + code instead of a bare number.
  • Completed the standard SPL Token error table (codes 0–19). Error 17 = AccountFrozen → "Token account is frozen" (verified against spl-token-interface source).

Context

Reported: a recurring-delegation pull on devnet failed with "Program error 17". Confirmed the destination token account was frozen (Token-2022 mint). The old message surfaced the raw code; this makes it readable and correctly scoped to the emitting program.

Test Plan

  • prettier --check clean.
  • pnpm --filter webapp exec tsc -b passes (webapp typechecks clean with the change).
  • Change is isolated to webapp/src/lib/parse-program-error.ts.

parseProgramError applied the SPL Token error table to any unmapped
custom error code, so e.g. an error 17 from a non-token program would
mislabel as 'Token account is frozen'. Attribute the code to the failing
program (subscriptions vs SPL Token / Token-2022) before mapping, and
fall back to naming the program + code when it can't be attributed.
Also complete the standard SPL Token error table (codes 0-19).
@vercel
Copy link
Copy Markdown

vercel Bot commented Jun 4, 2026

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

Project Deployment Actions Updated (UTC)
solana-subscriptions-program Ready Ready Preview, Comment Jun 4, 2026 3:39pm

Request Review

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 4, 2026

Compute Unit Report

Instruction Samples Min CUs Max CUs Avg CUs Est Cost (Low) [SOL] Est Cost (Med) [SOL] Est Cost (High) [SOL]
cancel_subscription 22 1720 2030 1919 0.000005000 0.000005076 0.000005959
close_subscription_authority 10 1803 1833 1806 0.000005000 0.000005072 0.000005903
create_fixed_delegation 41 3520 14022 5631 0.000005001 0.000005225 0.000007815
create_plan 97 3436 15449 5542 0.000005001 0.000005221 0.000007771
create_recurring_delegation 30 3550 17053 5806 0.000005001 0.000005232 0.000007903
delete_plan 9 359 359 359 0.000005000 0.000005014 0.000005179
init_subscription_authority 174 6226 22726 9342 0.000005002 0.000005373 0.000009671
resume_subscription 3 1723 1723 1723 0.000005000 0.000005068 0.000005861
revoke_delegation 19 255 519 353 0.000005000 0.000005014 0.000005176
subscribe 32 6485 15485 8132 0.000005002 0.000005325 0.000009066
transfer_fixed 9 5479 11466 7031 0.000005002 0.000005281 0.000008515
transfer_recurring 20 5591 16078 7292 0.000005002 0.000005291 0.000008646
transfer_subscription 10 5799 8931 6593 0.000005001 0.000005263 0.000008296
update_plan 22 424 503 477 0.000005000 0.000005019 0.000005238

Generated: 2026-06-04

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Jun 4, 2026

Greptile Summary

This PR fixes a bug in parseProgramError where any unrecognised custom error code was mapped against the SPL Token error table regardless of which program actually threw it. The fix attributes each code to its emitting program before looking it up.

  • Replaces the old programAddress? parameter with automatic attribution: the function now compares the failing program extracted from the error message against the IDL publicKey (subscriptions), TOKEN_PROGRAM_ADDRESS, and TOKEN_2022_PROGRAM_ADDRESS.
  • Completes the SPL Token error table from 4 entries to the full 0–19 range; error 17 (AccountFrozen) is the specific code that triggered the bug report.
  • The removed programAddress? parameter had no callers passing a value, so the signature change is safe.

Confidence Score: 4/5

Safe to merge; the fix correctly scopes error codes to their emitting program and resolves the reported frozen-account mislabelling.

The core attribution logic is correct and well-structured. The one thing to watch is the no-attribution fallback (line 60): when the error message lacks a "Program X failed:" line, SPL token errors in the 0–19 range are no longer resolved to friendly strings, which is a regression from the old behaviour. This is a narrow edge case in practice but worth addressing before shipping.

webapp/src/lib/parse-program-error.ts — specifically the final fallback branch and its interaction with the SPL token error table.

Important Files Changed

Filename Overview
webapp/src/lib/parse-program-error.ts Rewrites error attribution logic to scope custom error codes to their emitting program (subscriptions IDL, SPL Token, Token-2022); extends the SPL token table to codes 0–19. One narrow regression: the no-attribution fallback path no longer maps SPL token errors.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[parseProgramError called] --> B{error instanceof Error?}
    B -- No --> C[return 'Unknown error']
    B -- Yes --> D{hex or decimal error code match?}
    D -- No --> E[return error.message]
    D -- Yes --> F[extract failedProgram from error message]
    F --> G{failedProgram === PROGRAM_ADDRESS?}
    G -- Yes --> H[PROGRAM_ERRORS lookup or 'Subscriptions program error N']
    G -- No --> I{TOKEN_PROGRAM_IDS.has failedProgram?}
    I -- Yes --> J[SPL_TOKEN_ERRORS lookup or 'Token program error N']
    I -- No --> K{failedProgram non-empty?}
    K -- Yes --> L[return 'Program X error N']
    K -- No --> M[PROGRAM_ERRORS lookup or 'Program error N']
Loading

Reviews (1): Last reviewed commit: "fix(webapp): map custom errors per faili..." | Re-trigger Greptile

Comment thread webapp/src/lib/parse-program-error.ts
@dev-jodee dev-jodee merged commit 2c6e710 into main Jun 4, 2026
15 checks passed
@dev-jodee dev-jodee deleted the fix/transfer-missing-delegatee-token-account branch June 4, 2026 15:51
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