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
/effectexports)
Basic Pattern
Constructors throw when given invalid input:Error Hierarchy
All errors extendPrimitiveError:
Error Metadata
Every error includes debugging information:| Field | Type | Description |
|---|---|---|
name | string | Error class name |
code | string | Machine-readable code |
value | unknown | The invalid input |
expected | string | What was expected |
docsPath | string | Link to documentation |
context | object | Additional debug info |
cause | Error | Original error (if wrapped) |
Validation Functions
Three ways to validate:- Constructor: When invalid input is unexpected
- isValid: When you want to branch on validity
- assert: When you need validation options (like
strictchecksum)
Checking Error Types
Useinstanceof to check error types:
code field for simpler handling:
Effect.ts Integration
For advanced use cases, Voltaire provides Effect.ts schemas:Data.TaggedError:
@tevm/voltaire/effect subpath. Regular usage just throws standard exceptions.
Schema Error Messages
When using Effect schemas, useformatError from effect/ParseResult to get human-readable error messages:
Error Message Guidelines
When implementing schema annotations, follow these guidelines:| Guideline | Example |
|---|---|
| ✅ Include expected format/length | "Expected 40 hex characters" |
| ✅ Include what was received | "got 4 characters" |
| ❌ Never include actual value for sensitive types | PrivateKey, Mnemonic |
| ❌ Avoid raw predicate failures | "Predicate refinement failure" |
Custom Message Annotations
Use.annotations({ message }) to provide helpful error messages:
formatError API
TheformatError function from effect/ParseResult renders parse errors as human-readable trees:
Testing Schema Errors
Iterate on schema error messages to ensure good UX:Sensitive Types
Never expose actual values in error messages for sensitive types:PrivateKeyMnemonicSeedPhrase- Any key material

