class ErrorUtils

Error utility functions providing consistent error handling across the codebase.

Static Methods

configurationError(
message: string,
configName?: string,
): ConfigurationError

Creates a ConfigurationError for invalid configurations.

fileNotFoundError(path: string): FileSystemError

Creates a FileSystemError for file not found.

format(error: unknown): string

Creates a formatted error stack for logging. Includes cause chain if available.

getErrorCode(error: unknown): ErrorCode | undefined

Gets the error code if the error is a BaseError, otherwise returns undefined.

getMessage(error: unknown): string

Extracts error message from unknown error type. This is the standard way to get error messages - use this instead of inline checks.

httpError(
url: string,
statusCode: number,
statusText: string,
): NetworkError

Creates a NetworkError for HTTP failures.

isBaseError(error: unknown): error is BaseError

Checks if an error is a BaseError (custom application error).

isConfigurationError(error: unknown): error is ConfigurationError

Checks if an error is a ConfigurationError.

isNetworkError(error: unknown): error is NetworkError

Checks if an error is a NetworkError.

isRetryable(error: unknown): boolean

Checks if an error is retryable (network-related). Use this to determine if an operation should be retried.

isValidationError(error: unknown): error is ValidationError

Checks if an error is a ValidationError.

permissionDeniedError(
path: string,
operation: string,
): FileSystemError

Creates a FileSystemError for permission denied.

sourceDownloadError(
source: string,
cause?: Error,
): SourceError

Creates a SourceError for source download failures.

storageError(
operation: string,
key?: string[],
cause?: Error,
): StorageError

Creates a StorageError for storage operations.

timeoutError(
url: string,
timeoutMs: number,
): NetworkError

Creates a NetworkError for timeout failures.

toError(error: unknown): Error

Converts unknown error to Error instance. Preserves the original error if it's already an Error.

transformationError(
transformationType: string,
message: string,
ruleCount?: number,
cause?: Error,
): TransformationError

Creates a TransformationError for transformation failures.

wrap(
error: unknown,
context: string,
): Error

Wraps an error with additional context. Use this to add context when re-throwing errors.