/** * KHAELOR * File: src/shared/errors.ts * Description: Typed error base — every KHAELOR failure carries a stable machine-readable code. * * Author: Simon-Pierre Boucher * Contact: contact@spboucher.ai */ /** Stable machine-readable error codes used across modules. */ export type KhaelorErrorCode = | "config-invalid" | "config-io" | "session-log-corrupted" | "session-log-io" | "store-write-failed" | "pairing-violation" | "invalid-event" | "internal"; /** * Base error type. Messages must never contain secrets (API keys, * authorization headers) — callers are responsible for redaction * before constructing the message. */ export class KhaelorError extends Error { readonly code: KhaelorErrorCode; readonly details: Readonly>; constructor(code: KhaelorErrorCode, message: string, details: Record = {}) { super(message); this.name = "KhaelorError"; this.code = code; this.details = details; } } /** Narrowing helper. */ export function isKhaelorError(value: unknown): value is KhaelorError { return value instanceof KhaelorError; }