Skip to content

feat: typed error handling for wallet hooks (#44)#54

Merged
satoshai-dev merged 1 commit intomainfrom
feat/typed-errors
Mar 5, 2026
Merged

feat: typed error handling for wallet hooks (#44)#54
satoshai-dev merged 1 commit intomainfrom
feat/typed-errors

Conversation

@satoshai-dev
Copy link
Copy Markdown
Owner

Summary

Adds wagmi-style typed error classes for all wallet hooks, replacing plain Error throws:

  • BaseError — base class with shortMessage, details, and walk() for cause chain traversal
  • WalletNotConnectedError — thrown when calling a hook without an active connection
  • WalletNotFoundError — thrown when wallet extension is not installed (OKX)
  • UnsupportedMethodError — thrown for unsupported wallet methods (e.g. OKX + stx_signStructuredMessage), exposes method and wallet
  • WalletRequestError — wraps wallet RPC failures with method, wallet, and original cause

Each error exports a *ErrorType for TypeScript discriminated unions via error.name.

Developer experience

const { error } = useSignStructuredMessage()

if (error instanceof UnsupportedMethodError) {
  toast(`${error.wallet} doesn't support ${error.method}`)
}

// Or via name discrimination
if (error?.name === 'WalletRequestError') {
  console.log(error.method, error.wallet, error.cause)
}

Closes #44

Files changed

  • New: packages/kit/src/errors.ts — error class definitions
  • Modified: 5 hooks — useSignMessage, useSignStructuredMessage, useSignTransaction, useTransferSTX, useWriteContract
  • Modified: packages/kit/src/index.ts — exports all error classes and types
  • Modified: 4 test files — updated assertions to use shortMessage

Test plan

  • All 144 tests pass
  • Build, lint, typecheck pass

🤖 Generated with Claude Code

Add wagmi-style typed errors: BaseError, WalletNotConnectedError,
WalletNotFoundError, UnsupportedMethodError, WalletRequestError.

All hooks now throw typed errors with shortMessage, details, walk(),
and name-based discrimination. Developers can use instanceof or
error.name checks for specific error handling.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@satoshai-dev satoshai-dev merged commit 059b504 into main Mar 5, 2026
1 check passed
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.

Add typed error handling for unsupported wallet methods

1 participant