/**
 * Totem error class hierarchy.
 *
 * Every Totem error includes:
 * - A clear message with [Totem Error] prefix
 * - A recoveryHint telling the user exactly how to fix it
 * - A code for programmatic handling
 */
export class TotemError extends Error {
    code;
    recoveryHint;
    constructor(code, message, recoveryHint, cause) {
        super(`[Totem Error] ${message}`, { cause });
        this.name = 'TotemError';
        this.code = code;
        this.recoveryHint = recoveryHint;
    }
}
export class TotemConfigError extends TotemError {
    constructor(message, recoveryHint, code = 'CONFIG_MISSING', cause) {
        super(code, message, recoveryHint, cause);
        this.name = 'TotemConfigError';
    }
}
export class TotemDatabaseError extends TotemError {
    constructor(message, recoveryHint, code = 'DATABASE_CORRUPT', cause) {
        super(code, message, recoveryHint, cause);
        this.name = 'TotemDatabaseError';
    }
}
export class TotemCompileError extends TotemError {
    constructor(message, recoveryHint, cause) {
        super('COMPILE_FAILED', message, recoveryHint, cause);
        this.name = 'TotemCompileError';
    }
}
export class TotemParseError extends TotemError {
    constructor(message, recoveryHint, cause) {
        super('PARSE_FAILED', message, recoveryHint, cause);
        this.name = 'TotemParseError';
    }
}
export class TotemOrchestratorError extends TotemError {
    constructor(message, recoveryHint, cause) {
        super('ORCHESTRATOR_UNAVAILABLE', message, recoveryHint, cause);
        this.name = 'TotemOrchestratorError';
    }
}
export class TotemGitError extends TotemError {
    constructor(message, recoveryHint, cause) {
        super('GIT_FAILED', message, recoveryHint, cause);
        this.name = 'TotemGitError';
    }
}
// ─── Utilities ──────────────────────────────────────
/** Extract a human-readable message from an unknown thrown value. */
export function getErrorMessage(err) {
    return err instanceof Error ? err.message : String(err);
}
/**
 * Re-throw as TotemParseError, preserving already-wrapped errors.
 * Use in catch blocks where AST engine failures must fail-closed.
 */
export function rethrowAsParseError(label, err, hint) {
    if (err instanceof TotemParseError)
        throw err;
    throw new TotemParseError(`${label}: ${getErrorMessage(err)}`, hint, err); // totem-ignore — #848: TotemError constructor auto-prepends [Totem Error]
}
//# sourceMappingURL=errors.js.map