Skip to main content
Voltaire uses viem-style errors—synchronous exceptions with rich metadata for debugging. This pattern, pioneered by viem, provides machine-readable error codes alongside human-readable messages.

Why Exceptions?

Voltaire primitives stay close to TypeScript and Ethereum specifications. Since JavaScript’s native APIs throw exceptions (e.g., JSON.parse, new URL), Voltaire follows the same pattern for consistency. However, we recommend wrapping Voltaire in more error-safe patterns for application code:
  • neverthrow — Lightweight Result type for TypeScript
  • Effect.ts — Full-featured typed effects system (Voltaire provides /effect exports)

Basic Pattern

Constructors throw when given invalid input:
Use try/catch to handle errors:

Error Hierarchy

All errors extend PrimitiveError:

Error Metadata

Every error includes debugging information:

Validation Functions

Three ways to validate:
Choose based on your use case:
  • Constructor: When invalid input is unexpected
  • isValid: When you want to branch on validity
  • assert: When you need validation options (like strict checksum)

Checking Error Types

Use instanceof to check error types:
Or check the code field for simpler handling:

Effect.ts Integration

For advanced use cases, Voltaire provides Effect.ts schemas:
Effect.ts errors use Data.TaggedError:
Effect.ts is optional—imported from @tevm/voltaire/effect subpath. Regular usage just throws standard exceptions.

Schema Error Messages

When using Effect schemas, use formatError from effect/ParseResult to get human-readable error messages:

Error Message Guidelines

When implementing schema annotations, follow these guidelines:

Custom Message Annotations

Use .annotations({ message }) to provide helpful error messages:

formatError API

The formatError function from effect/ParseResult renders parse errors as human-readable trees:
Output format is a tree showing the path to the error:

Testing Schema Errors

Iterate on schema error messages to ensure good UX:

Sensitive Types

Never expose actual values in error messages for sensitive types:
Sensitive types include:
  • PrivateKey
  • Mnemonic
  • SeedPhrase
  • Any key material

Learn More

Address Validation

Address-specific error handling

Type-Safe Values

Prevent errors with typed values