import type { ExpressionErrorReason } from "@uicast/expr"; /** * What failed: an expression's refusal or failure (an `ExpressionErrorReason`), or an element-level one. * * @example * if (error.reason === "unknown-component") return

No implementation for {error.elementKey}

; */ export type EntryErrorReason = ExpressionErrorReason | "invalid-entry" | "unknown-component" | "invalid-list" | "invalid-props" | "host-init" | "implementation" | "unknown"; /** * Whose code must fix a failure: `"document"` the model's (re-emit the entry), `"environment"` the host's, `"unknown"` * either. * * @example * const fault: EntryFault = error.fault; // "document" for reason "invalid-props" */ export type EntryFault = "document" | "environment" | "unknown"; export declare const FAULT_BY_REASON: Record; export declare const REASON_DESCRIPTIONS: Record; /** * The classified error every element failure arrives as, in the error slot and in `onError`. `reason` says what * failed; `fault` says whose code must fix it. * * @example * const onError = (error: EntryError) => * error.fault === "document" ? askModelToFix(error.elementKey, error.message) : report(error); */ export declare class EntryError extends Error { /** What failed, e.g. `"invalid-props"`. */ readonly reason: EntryErrorReason; /** The key of the element that failed. The error boundary fills it in when the throw site could not. */ elementKey?: string; /** Brand for `EntryError.is`: `instanceof` fails when two copies of this package share a bundle. */ readonly uicastEntryError = true; constructor(message: string, options: { reason: EntryErrorReason; elementKey?: string; cause?: unknown; }); /** Whose code must fix it: `"document"` (the model, by re-emitting), `"environment"` (host code) or `"unknown"`. */ get fault(): EntryFault; /** * Whether `err` is an `EntryError`, from any copy of this package. Use it over `instanceof`. * * @example * if (EntryError.is(err)) console.warn(err.reason, err.elementKey); */ static is(err: unknown): err is EntryError; /** * Turns any thrown value into an `EntryError` with this `reason`. An `EntryError` passes through as is, and gets * `elementKey` if it had none. * * @example * const error = EntryError.wrap(err, "implementation", "orders-table"); * error.fault; // "environment" */ static wrap(err: unknown, reason: EntryErrorReason, elementKey?: string): EntryError; }