Skip to content

armgit / Pake

Public Imported from GitHub
0

Turn any website into a lightweight desktop app with one command, on macOS, Windows and Linux.

1.0 KB
Raw Blame
import type { PakeErrorCode } from './output';

/**
 * Error class used for user-facing CLI errors.
 *
 * The top-level catch in `bin/cli.ts` prints `message` directly without a
 * stack trace and exits with the code mapped from `code` (see
 * ERROR_EXIT_CODES in utils/output.ts). Use this for predictable failures
 * (invalid names, missing files, etc.) so users see a clean message instead
 * of a Node.js stack dump. `code` and `hint` also feed the `--json` result.
 */
export class PakeError extends Error {
  readonly isUserError = true;
  readonly code?: PakeErrorCode;
  readonly hint?: string;

  constructor(
    message: string,
    options?: { code?: PakeErrorCode; hint?: string },
  ) {
    super(message);
    this.name = 'PakeError';
    this.code = options?.code;
    this.hint = options?.hint;
  }
}

export function isPakeError(error: unknown): error is PakeError {
  return (
    error instanceof PakeError ||
    (typeof error === 'object' &&
      error !== null &&
      (error as { isUserError?: boolean }).isUserError === true)
  );
}