Skip to content

Typed error taxonomy + custom error classes #18

@truthixify

Description

@truthixify

Labels: Stellar Wave, dx, feature, drips, help-wanted
Tier: M (2–4 days)
Type: feature / dx

Context

The SDK throws plain Error instances everywhere. A consumer catching one cannot programmatically distinguish "invalid meta-address format" from "RPC unreachable" from "view tag mismatch" — they have to substring-match on the message, which is brittle and breaks across versions.

We want a typed error hierarchy so consumers can catch (e) { if (e instanceof WraithNameNotFoundError) ... }.

Scope

Define a hierarchy at sdk/src/errors.ts:

WraithError (abstract base)
├── WraithInputError
│   ├── InvalidMetaAddressError
│   ├── InvalidNameError
│   ├── InvalidSignatureError
│   └── InvalidScalarError
├── WraithCryptoError
│   ├── KeyDerivationFailedError
│   ├── ViewTagMismatchError
│   └── ECDHFailedError
├── WraithNetworkError
│   ├── RPCRequestError (carries status code)
│   ├── RPCRetryExhaustedError
│   └── RetentionExceededError
├── WraithContractError
│   ├── NameNotFoundError
│   ├── NameAlreadyRegisteredError
│   ├── InsufficientAuthError
│   └── ContractRevertError (carries decoded reason)
└── WraithBuilderError
    ├── InsufficientBalanceError
    └── UnsupportedAssetError

Each subclass:

  • Has a name matching the class name.
  • Carries domain-specific structured data on the instance (not just in the message).
  • Has a stable code constant string for serialization across runtime boundaries (e.g., "WRAITH/CRYPTO/VIEW_TAG_MISMATCH").
  • Includes a human-readable message with a docs link.

Migration

  • Sweep the codebase replacing throw new Error(...) with the correct typed throw.
  • Update JSDoc @throws annotations (coordinate with issue #10).
  • Add a CHANGELOG.md entry noting the migration is non-breaking at runtime (subclasses extend Error) but typing-breaking for try { } catch (e: any) { e.message } patterns that assume the specific message format.

Tests

  • One unit test per error class verifying instanceof correctness across both ESM and CJS builds.
  • A check that JSON-serializing an error preserves code.

Acceptance criteria

  • Error hierarchy implemented and exported.
  • Codebase swept to use typed throws.
  • JSDoc @throws annotations updated.
  • Tests covering instanceof + serialization.
  • Docs page added explaining the hierarchy (under SDK docs).

Why this matters

Good error types are the difference between a library that integrators can build around and one that they have to monkey-patch. Every Spectre / demo / console error-handling branch becomes more robust the moment this lands.

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programdripsFunded via Drips NetworkdxDeveloper experiencefeatureNew feature workhelp wantedExtra attention is needed

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions