Component evidence
Defines a custom CLI error class and helper function to format unexpected errors and argument parsing failures. Reuse when building command-line interfaces.
// Source: https://github.com/pascalorg/editor | License: MIT | Copyright 2026 Pascal Group Inc
// Provided via justclaw.it.com; keep this notice with the code.
export class CliError extends Error {
readonly code: string
readonly details?: unknown
readonly exitCode: number
constructor(code: string, message: string, details?: unknown, exitCode = 1) {
super(message)
this.name = 'CliError'
this.code = code
this.details = details
this.exitCode = exitCode
}
}
export function toCliError(error: unknown): CliError {
if (error instanceof CliError) return error
const nodeCode = (error as { code?: unknown })?.code
if (typeof nodeCode === 'string' && nodeCode.startsWith('ERR_PARSE_ARGS_')) {
return new CliError(
'invalid_option',
error instanceof E
... (truncated -- full source via MCP)