/** * Error Wrapping Utilities * * Provides utilities for wrapping unknown errors as VeryfrontError instances * with the unknown-error slug. Used at system boundaries to ensure all errors * have slug-based identity. * * @module errors/middleware/wrap-unknown */ import { VeryfrontError } from "../types.js"; /** * Return a detached VeryfrontError, preserving safe identity fields from valid VeryfrontError inputs * * This function is used at system boundaries (HTTP, CLI, etc.) to ensure * all errors have slug-based identity for consistent handling. * * @param error - A valid VeryfrontError to detach, or another value to wrap as unknown-error * @param context - Optional context added only when error is not a valid VeryfrontError * @returns A detached, framework-owned VeryfrontError. Valid VeryfrontError * inputs retain safe identity fields; other inputs use the unknown-error slug. * * @example * ```typescript * try { * // Some operation * } catch (error) { * const vfError = wrapUnknownError(error); * return createErrorResponse(vfError); * } * ``` */ export declare function wrapUnknownError(error: unknown, context?: Record): VeryfrontError; /** * Detach a thrown value at a system boundary, then normalize the stable copy. * * This prevents stateful Error proxies from reporting different identities to * observability, formatting, and the final response. */ export declare function detachBoundaryError(error: unknown): VeryfrontError; /** * Wrap an error with additional context * * If the error is already a VeryfrontError, preserves its slug and adds context. * If the error is a plain Error, wraps it as unknown-error. * * @param error - Any error value * @param message - Additional message to prepend * @param context - Additional context to add * @returns VeryfrontError with added context * * @example * ```typescript * try { * await fetchData(); * } catch (error) { * throw wrapWithContext(error, "Failed to fetch data", { userId: 123 }); * } * ``` */ export declare function wrapWithContext(error: unknown, message: string, context?: Record): VeryfrontError; //# sourceMappingURL=wrap-unknown.d.ts.map