{"version":3,"file":"errors.mjs","names":[],"sources":["../../src/core/errors.ts"],"sourcesContent":["/**\n * Structured error hierarchy for Padrone CLI framework.\n *\n * All Padrone errors extend `PadroneError`, which carries an exit code,\n * optional suggestions, and context about which command/phase produced the error.\n * This allows callers to distinguish user errors (bad input) from bugs (unexpected throws)\n * and to present formatted, actionable error messages.\n */\n\nimport type { PadroneSignal } from './runtime.ts';\n\nexport type PadroneErrorOptions = {\n  /** Process exit code. Defaults to 1. */\n  exitCode?: number;\n  /** Actionable suggestions shown to the user (e.g. \"Use --env production\"). */\n  suggestions?: string[];\n  /** The command path that produced the error (e.g. \"deploy staging\"). */\n  command?: string;\n  /** The phase where the error occurred. */\n  phase?: 'parse' | 'validate' | 'execute' | 'config';\n  /** Original cause for error chaining. */\n  cause?: unknown;\n};\n\n/**\n * Base error class for all Padrone errors.\n * Carries structured metadata for user-friendly formatting and programmatic handling.\n *\n * @example\n * ```ts\n * throw new PadroneError('Something went wrong', {\n *   exitCode: 1,\n *   suggestions: ['Try --help for usage information'],\n * });\n * ```\n */\nexport class PadroneError extends Error {\n  readonly exitCode: number;\n  readonly suggestions: string[];\n  readonly command?: string;\n  readonly phase?: 'parse' | 'validate' | 'execute' | 'config';\n\n  constructor(message: string, options?: PadroneErrorOptions) {\n    super(message, options?.cause ? { cause: options.cause } : undefined);\n    this.name = 'PadroneError';\n    this.exitCode = options?.exitCode ?? 1;\n    this.suggestions = options?.suggestions ?? [];\n    this.command = options?.command;\n    this.phase = options?.phase;\n  }\n\n  /**\n   * Returns a serializable representation of the error,\n   * suitable for non-terminal runtimes (web UIs, APIs, etc.).\n   */\n  toJSON(): {\n    name: string;\n    message: string;\n    exitCode: number;\n    suggestions: string[];\n    command?: string;\n    phase?: string;\n  } {\n    return {\n      name: this.name,\n      message: this.message,\n      exitCode: this.exitCode,\n      suggestions: this.suggestions,\n      command: this.command,\n      phase: this.phase,\n    };\n  }\n}\n\n/**\n * Thrown when command routing fails — unknown command, unexpected arguments, etc.\n */\nexport class RoutingError extends PadroneError {\n  constructor(message: string, options?: PadroneErrorOptions) {\n    super(message, { phase: 'parse', ...options });\n    this.name = 'RoutingError';\n  }\n}\n\n/**\n * Thrown when argument or schema validation fails.\n * Carries the structured issues from the schema validator.\n */\nexport class ValidationError extends PadroneError {\n  readonly issues: readonly { path?: PropertyKey[]; message: string }[];\n\n  constructor(message: string, issues: readonly { path?: PropertyKey[]; message: string }[], options?: PadroneErrorOptions) {\n    super(message, { phase: 'validate', ...options });\n    this.name = 'ValidationError';\n    this.issues = issues;\n  }\n\n  override toJSON() {\n    return {\n      ...super.toJSON(),\n      issues: this.issues.map((i) => ({ path: i.path?.map(String), message: i.message })),\n    };\n  }\n}\n\n/**\n * Thrown when config file loading or validation fails.\n */\nexport class ConfigError extends PadroneError {\n  constructor(message: string, options?: PadroneErrorOptions) {\n    super(message, { phase: 'config', ...options });\n    this.name = 'ConfigError';\n  }\n}\n\n/**\n * Thrown from user action handlers to surface structured errors with exit codes and suggestions.\n * This is the primary error class users should throw from their command actions.\n *\n * @example\n * ```ts\n * throw new ActionError('Missing environment', {\n *   exitCode: 1,\n *   suggestions: ['Use --env production or --env staging'],\n * });\n * ```\n */\nexport class ActionError extends PadroneError {\n  constructor(message: string, options?: PadroneErrorOptions) {\n    super(message, { phase: 'execute', ...options });\n    this.name = 'ActionError';\n  }\n}\n\n/**\n * Thrown when command execution is interrupted by a process signal (SIGINT, SIGTERM, SIGHUP).\n * Carries the signal name and the conventional exit code (128 + signal number).\n */\nexport class SignalError extends PadroneError {\n  readonly signal: PadroneSignal;\n\n  constructor(signal: PadroneSignal, options?: { cause?: unknown }) {\n    super(`Process interrupted by ${signal}`, { exitCode: signalExitCode(signal), cause: options?.cause });\n    this.name = 'SignalError';\n    this.signal = signal;\n  }\n}\n\n/** Maps a signal name to its conventional exit code (128 + signal number). */\nexport function signalExitCode(signal: PadroneSignal): number {\n  const codes: Record<string, number> = { SIGINT: 130, SIGTERM: 143, SIGHUP: 129 };\n  return codes[sign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