/** Shared error type so every failure path carries a status/hint the tool and command can print. */
export class JevError extends Error {
  readonly status: number | undefined;
  readonly hint: string | undefined;
  readonly body: string | undefined;

  constructor(message: string, options: { status?: number; hint?: string; body?: string; cause?: unknown } = {}) {
    super(message, options.cause === undefined ? undefined : { cause: options.cause });
    this.name = "JevError";
    this.status = options.status;
    this.hint = options.hint;
    this.body = options.body;
  }
}

export function messageOf(error: unknown): string {
  return error instanceof Error ? error.message : String(error);
}
