import { SuaveplanError, type SuaveplanErrorOptions } from "@suaveplan/error"; import { TEMPLATE_CODES, type TemplateCode } from "./error-codes.js"; export type { TemplateCode }; export { TEMPLATE_CODES }; // ─── Base ─────────────────────────────────────────────────────────────────── /** * Base error class for all template engine failures. * * Carries the original `template` string and the `renderContext` object so * callers can log rich diagnostics without re-parsing the call-stack. */ export class TemplateError extends SuaveplanError { public readonly template: string; public readonly renderContext: Record; constructor( code: TemplateCode, messageKey: string, template: string, renderContext: Record, options?: SuaveplanErrorOptions ) { super(code, messageKey, options); this.template = template; this.renderContext = renderContext; } } // ─── Plugin error ──────────────────────────────────────────────────────────── /** * Emitted when a plugin's `transform()` throws or returns a rejected Promise. * * Adds `pluginName` and `matchedText` for quick diagnostics. */ export class PluginError extends SuaveplanError { public readonly pluginName: string; public readonly match: string; constructor( message: string, pluginName: string, match: string, cause?: Error ) { super( TEMPLATE_CODES.PLUGIN_ERROR, message, cause ? { cause } : undefined ); this.pluginName = pluginName; this.match = match; } } // ─── Max depth error ───────────────────────────────────────────────────────── /** * Thrown when recursive template nesting exceeds `TemplateEngineOptions.maxDepth`. * * Includes `depth` (current) and `maxDepth` (limit) for diagnostics. */ export class MaxDepthError extends SuaveplanError { public readonly depth: number; public readonly maxDepth: number; constructor(message: string, depth: number, maxDepth: number) { super(TEMPLATE_CODES.MAX_DEPTH, message); this.depth = depth; this.maxDepth = maxDepth; } }