// src/utils/errors.ts
var ExitCode = {
  /** Command completed successfully */
  SUCCESS: 0,
  /** Command failed because of a validation error (e.g. check-docs found issues) */
  VALIDATION_FAILED: 1,
  /** Command failed because of an unexpected error or misconfiguration */
  ERROR: 2
};
var CLIError = class extends Error {
  /** The exit code associated with this error */
  exitCode;
  /**
   * Creates a new CLIError.
   *
   * @param message - Human-readable error message.
   * @param exitCode - Exit code to use when process terminates. Defaults to ExitCode.ERROR.
   */
  constructor(message, exitCode = ExitCode.ERROR) {
    super(message);
    this.name = "CLIError";
    this.exitCode = exitCode;
  }
};
function formatError(error) {
  if (error instanceof CLIError) {
    return `Error: ${error.message}`;
  }
  if (error instanceof Error) {
    return `Error: ${error.message}`;
  }
  return `Error: ${String(error)}`;
}
function handleError(error) {
  const message = formatError(error);
  console.error(message);
  const exitCode = error instanceof CLIError ? error.exitCode : ExitCode.ERROR;
  process.exit(exitCode);
}

export {
  ExitCode,
  CLIError,
  handleError
};
