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.
shortMessage
string
required
The short, human-readable error message (without details)
options
BaseError.Options
Configuration options for the error
name
string
The error name: 'Incur.BaseError'
shortMessage
string
The short, human-readable error message
details
string | undefined
Details extracted from the cause’s message, if any
message
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.
fn
(error: unknown) => boolean
Optional predicate function to find a specific error in the cause chain
return
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.
options
IncurError.Options
required
Configuration options for the error
name
string
The error name: 'Incur.IncurError'
code
string
Machine-readable error code (e.g., 'NOT_AUTHENTICATED', 'RATE_LIMITED')
hint
string | undefined
Actionable hint for the user to resolve the error
retryable
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.
options
ValidationError.Options
required
Configuration options for the error
name
string
The error name: 'Incur.ValidationError'
fieldErrors
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).
options
ParseError.Options
required
Configuration options for the error
name
string
The error name: 'Incur.ParseError'

Usage

Usage: Parse Error Handling

Types

FieldError

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

BaseError.Options

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

IncurError.Options

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

ValidationError.Options

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

ParseError.Options

Options for constructing a ParseError.
message
string
required
Human-readable error message
cause
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: