← Files CUARARCHIVED FILE

scripts/lib/errors.mjs

747 Bytes · Oct 2, 2026 · 00:29 UTC

↓ Download file

export class CuarError extends Error {
  constructor(code, stage, message, options = {}) {
    super(message, options.cause ? { cause: options.cause } : undefined);
    this.name = "CuarError";
    this.code = code;
    this.stage = stage;
    this.retryable = Boolean(options.retryable);
    this.exitCode = options.exitCode ?? 7;
  }
}

export function asCuarError(error) {
  if (error instanceof CuarError) return error;
  return new CuarError(
    "internal_error",
    "internal",
    "CUAR encountered an unexpected internal error.",
    { cause: error, exitCode: 7 },
  );
}

export function limitationFromError(error) {
  const normalized = asCuarError(error);
  return {
    code: normalized.code,
    message: normalized.message,
  };
}

SHA-256: 3d8e122bc35cc95420c78e22a8ba0793a05bedc97b5047eac4ca18c2462739be