Skip to main content

Class: abstract ChiveError

Defined in: src/types/errors.ts:43

Base error class for all Chive errors.

Remarks​

All Chive errors should extend this class rather than the native Error class. This ensures consistent error code structure, enables error cause chaining for debugging, captures proper stack traces, and allows type discrimination via instanceof.

Never throw raw strings or objects; always use Error classes.

Example​

class CustomError extends ChiveError {
readonly code = 'CUSTOM_ERROR';

constructor(message: string) {
super(message);
}
}

throw new CustomError('Something went wrong');

Extends​

  • Error

Extended by​

Constructors​

new ChiveError()​

new ChiveError(message, cause?): ChiveError

Defined in: src/types/errors.ts:79

Creates a new ChiveError.

Parameters​

message​

string

Human-readable error message

cause?​

Error

Original error (if chained)

Returns​

ChiveError

Overrides​

Error.constructor

Properties​

cause?​

readonly optional cause: Error

Defined in: src/types/errors.ts:71

Original error that caused this error (if any).

Remarks​

Error chaining allows tracking the full error context through multiple layers of the application. Useful for debugging complex error scenarios.

Example​

try {
await fetchData();
} catch (err) {
throw new ValidationError('Failed to validate data', 'field', 'required', err as Error);
}

Overrides​

Error.cause


code​

abstract readonly code: string

Defined in: src/types/errors.ts:52

Machine-readable error code.

Remarks​

Error codes are unique identifiers for error types, enabling programmatic error handling (switch statements, error maps), error tracking in monitoring systems, and client-side error translation (i18n).