Errors module provides a hierarchy of error classes designed for CLI applications, with support for error chaining, structured field errors, and machine-readable error codes.
Classes
BaseError
Base error class with support for short messages, detail extraction from cause chains, and cause traversal.The short, human-readable error message (without details)
Configuration options for the error
The error name:
'Incur.BaseError'The short, human-readable error message
Details extracted from the cause’s message, if any
The full error message, combining shortMessage and details
Usage
Method: walk
Traverses the cause chain. Without a callback, returns the deepest cause. With a callback, returns the first cause where the callback returnstrue.
Optional predicate function to find a specific error in the cause chain
The deepest cause (no callback) or the first matching cause (with callback)
IncurError
CLI-specific error with machine-readable error codes, actionable hints, and retry flags.Configuration options for the error
The error name:
'Incur.IncurError'Machine-readable error code (e.g.,
'NOT_AUTHENTICATED', 'RATE_LIMITED')Actionable hint for the user to resolve the error
Whether the operation can be retried. Defaults to
false.Usage
Usage: Retryable Errors
Usage: Error Codes
ValidationError
Validation error with per-field error details, typically thrown by the parser when Zod validation fails.Configuration options for the error
The error name:
'Incur.ValidationError'Array of per-field validation errors
Usage
Usage: Display Field Errors
ParseError
Error thrown when argument parsing fails (unknown flags, missing values, invalid syntax).Configuration options for the error
The error name:
'Incur.ParseError'Usage
Usage: Parse Error Handling
Types
FieldError
A field-level validation error detail.The field path that failed validation (e.g.,
'email', 'user.address.zip')The expected value or type (e.g.,
'string', 'number', 'email format')The value that was received
Human-readable validation message
BaseError.Options
Options for constructing aBaseError.
The underlying cause of this error
IncurError.Options
Options for constructing anIncurError.
Machine-readable error code
Human-readable error message
Actionable hint for the user
Whether the operation can be retried. Defaults to
false.The underlying cause
ValidationError.Options
Options for constructing aValidationError.
Human-readable error message
Per-field validation errors
The underlying cause
ParseError.Options
Options for constructing aParseError.
Human-readable error message
The underlying cause
Error Hierarchy
All error classes extendBaseError, which extends the native Error class:

