Skip to content

feat(client): decode contract error codes into typed SDK errors - #366

Open
DammyAji wants to merge 2 commits into
crackedstudio:mainfrom
DammyAji:feat/281-decode-contract-errors
Open

feat(client): decode contract error codes into typed SDK errors#366
DammyAji wants to merge 2 commits into
crackedstudio:mainfrom
DammyAji:feat/281-decode-contract-errors

Conversation

@DammyAji

Copy link
Copy Markdown

Summary

Parses Error(Contract, #N) from Stellar RPC simulation and submission failures and maps them to typed error subclasses, so callers can use instanceof checks instead of parsing XDR dumps.

What changed

  • packages/client/src/errors.ts — Added 8 typed error subclasses (CircleNotFoundError, RoundNotFundedError, WrongRoundTagError, AlreadyClaimedError, InvalidProofError, RoundFullError, OverflowError, CircleCancelledError) matching the #[contracterror] enum in contracts/sharibo/src/lib.rs
  • packages/client/src/decodeError.ts (new) — Regex-based parser that walks the error cause chain to extract Error(Contract, #N) patterns and instantiate the correct typed subclass
  • packages/client/src/contract.ts — Added the missing withRetry helper for transient RPC errors; wrapped every call site (simulation + submission) so thrown errors are normalised via decodeContractError
  • app/src/App.tsx — toUiError now uses instanceof-based lookup with human-friendly messages for each contract error; no XDR string matching
  • docs/errors.md (new) — Shared error code table with codes, TypeScript class names, meanings, and sync guide
  • packages/client/src/decodeError.test.ts (new) — 17 vitest tests using recorded real RPC error payloads

Acceptance criteria

  • catch (e) { if (e instanceof AlreadyClaimedError) ... } works
  • toUiError in the app contains no string matching on XDR
  • All typed subclasses extend ContractError then ShariboError
  • Original error preserved as cause on every subclass
  • Unknown contract codes produce ContractError with the numeric code
  • Non-contract RPC errors wrapped as RpcError
  • 17 tests pass with recorded real RPC payloads

Closes #281

DammyAji and others added 2 commits August 31, 2026 02:44
Parse Error(Contract, #N) from Stellar RPC simulation and submission
failures and map them to typed error subclasses, so callers can use
instanceof checks instead of parsing XDR dumps.

- Add typed error subclasses for codes 1-8 (CircleNotFoundError,
  RoundNotFundedError, WrongRoundTagError, AlreadyClaimedError,
  InvalidProofError, RoundFullError, OverflowError, CircleCancelledError)
- Create decodeError.ts with regex-based parser that walks the error cause
  chain to find Error(Contract, #N) patterns
- Add withRetry helper for transient RPC errors (was referenced but missing)
- Wrap every call site in contract.ts so thrown errors are normalised
- Update toUiError in App.tsx to use instanceof-based lookup (no XDR
  string matching)
- Add docs/errors.md with shared error code table
- Add 17 vitest tests using recorded real RPC error payloads

Closes crackedstudio#281

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
@DammyAji

DammyAji commented Sep 1, 2026

Copy link
Copy Markdown
Author

hi @Otaiki1 please kindly review and merge. Thank you.

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.

Decode contract error codes from RPC failures into typed SDK errors

1 participant