Skip to main content
The 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.
string
required
The short, human-readable error message (without details)
BaseError.Options
Configuration options for the error
string
The error name: 'Incur.BaseError'
string
The short, human-readable error message
string | undefined
Details extracted from the cause’s message, if any
string
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 returns true.
(error: unknown) => boolean
Optional predicate function to find a specific error in the cause chain
unknown
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.
IncurError.Options
required
Configuration options for the error
string
The error name: 'Incur.IncurError'
string
Machine-readable error code (e.g., 'NOT_AUTHENTICATED', 'RATE_LIMITED')
string | undefined
Actionable hint for the user to resolve the error
boolean
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.
ValidationError.Options
required
Configuration options for the error
string
The error name: 'Incur.ValidationError'
FieldError[]
Array of per-field validation errors

Usage

Usage: Display Field Errors

ParseError

Error thrown when argument parsing fails (unknown flags, missing values, invalid syntax).
ParseError.Options
required
Configuration options for the error
string
The error name: 'Incur.ParseError'

Usage

Usage: Parse Error Handling

Types

FieldError

A field-level validation error detail.
string
The field path that failed validation (e.g., 'email', 'user.address.zip')
string
The expected value or type (e.g., 'string', 'number', 'email format')
string
The value that was received
string
Human-readable validation message

BaseError.Options

Options for constructing a BaseError.
Error | undefined
The underlying cause of this error

IncurError.Options

Options for constructing an IncurError.
string
required
Machine-readable error code
string
required
Human-readable error message
string | undefined
Actionable hint for the user
boolean | undefined
Whether the operation can be retried. Defaults to false.
Error | undefined
The underlying cause

ValidationError.Options

Options for constructing a ValidationError.
string
required
Human-readable error message
FieldError[] | undefined
Per-field validation errors
Error | undefined
The underlying cause

ParseError.Options

Options for constructing a ParseError.
string
required
Human-readable error message
Error | undefined
The underlying cause

Error Hierarchy

All error classes extend BaseError, which extends the native Error class:
This allows you to catch errors at different levels of specificity: