import type { VErrorOptions } from './types.ts'; /** * Serialises any Error to the canonical VError JSON shape so that the full * cause chain is preserved when errors are transmitted over RPC or stored in * logs. Plain `Error` instances (which would otherwise serialise to `{}`) * receive the same structure as VError: `name`, `message`, `shortMessage`, * `cause`, `info`. * * Called automatically by `VError.toJSON()`. Export it if you need to * serialise errors that are not necessarily VErrors themselves. * * Auto-sanitises RPC fetch errors (ethers v5/v6, viem) — any URL embedded * in `message`, `stack`, or `info.requestUrl` is reduced to its origin so * `?token=` query strings never reach the serialised output. The * caller does not have to remember to invoke `sanitiseRpcFetchError` * itself; every persistence path (logs via `@polygonlabs/logger`, status * routes, Firestore documents, Sentry events) that hands an error to * `serializeError` is safe by default. See `./sanitise.ts` for the * detection rules and how to extend them. */ export declare function serializeError(err: unknown): Record | undefined; export declare class VError extends Error { readonly name: string; /** * Returns the fully accumulated message for `cause`, walking native Error * cause chains so VError produces a complete message even when some links * are plain Errors that did not append their own cause message. * * VError instances already carry the full accumulated chain in `.message` * and are returned directly. WError is a VError whose `.message` is its * own message only (by design), so it naturally stops the accumulation. */ private static accumulateCauseMessage; /** The message as passed to the constructor, before the cause chain was appended. */ readonly shortMessage: string; /** * Structured informational properties attached at construction time. * Use `VError.info(err)` to get the merged set from the full cause chain. */ readonly info: Record; constructor(message: string, options?: VErrorOptions); toString(): string; toJSON(): Record; /** * Returns the immediate cause of `err`, or null. Unlike reading `err.cause` * directly (typed as `unknown` on the base Error class), this validates that * the cause is an actual Error and returns a typed result. */ static cause(err: Error): Error | null; /** * Returns the merged info object for the entire cause chain of `err`. * Deeper causes appear first; closer causes override their values. */ static info(err: Error): Record; /** Walk the cause chain and return the first Error whose `name` matches. */ static findCauseByName(err: Error, name: string): Error | null; /** * Walk the cause chain and return the first Error that is `instanceof type`. * * The constraint uses `{ prototype: T }` rather than a constructor signature * because TypeScript types built-in constructors (e.g. `Error`) with specific * parameter types like `(message?: string)`, which are not compatible with a * fully generic `new (...args: unknown[]) => T` form. `instanceof` only * inspects the prototype chain, so `{ prototype: T }` is the correct shape. */ static findCauseByType(err: Error, type: { prototype: T; }): T | null; static hasCauseWithName(err: Error, name: string): boolean; static hasCauseWithType(err: Error, type: { prototype: T; }): boolean; /** Concatenates the full stack trace including all chained causes. */ static fullStack(err: Error): string; /** * Given an array of errors, returns null (empty), the single error (one * item), or a new `MultiError` wrapping all of them. */ static errorFromList(errors: Error[]): Error | null; /** * Calls `func` once for each contained error: once for a plain Error, * once per element for a MultiError. */ static errorForEach(err: Error, func: (e: Error) => void): void; } /** * Cross-boundary identity marker for WError and its subclasses. * * Uses Symbol.for() so the same symbol is returned from the global registry * regardless of which module copy of @polygonlabs/verror is loaded — unlike * `instanceof`, which breaks when the host and a dependency have separate * copies of the class. * * Check with: `(err as Record)[WERROR_SYMBOL] === true` */ export declare const WERROR_SYMBOL: unique symbol; /** * Cross-boundary identity marker for MultiError and its subclasses. * * Uses Symbol.for() so the same symbol is returned from the global registry * regardless of which module copy of @polygonlabs/verror is loaded — unlike * `instanceof`, which breaks when the host and a dependency have separate * copies of the class. * * Check with: `(err as Record)[MULTIERROR_SYMBOL] === true` */ export declare const MULTIERROR_SYMBOL: unique symbol; /** * A "wrapped error" — like VError but the cause's message is intentionally * NOT appended to this error's own message. The cause is still traversable * via `VError.cause()` and serialised under `cause` by `serializeError` / * `toJSON`, but neither `.message` nor `.toString()` mention it. * * Use WError when you want to wrap a lower-level error with a distinct * higher-level description without the noise (or risk) of duplicating the * cause message. The boundary semantics are uniform across `.message` and * `.toString()` — anywhere the error is stringified, only its own message * surfaces. Code that wants the cause walks `err.cause` explicitly. * * Identity is signalled by `WERROR_SYMBOL` on this class's prototype (set * in the static block below). `VError`'s constructor reads it via * `new.target.prototype` during `super()` and suppresses cause-message * accumulation. Subclasses inherit the marker automatically — no custom * constructor or per-class wiring needed. */ export declare class WError extends VError { readonly name: string; constructor(message: string, options: VErrorOptions & { cause: Error; }); } /** * Represents a collection of errors for callers that normally deal with a * single error but need to surface multiple failures. The first error in the * list is used as the cause; all errors are accessible via `err.errors`. */ export declare class MultiError extends VError { readonly name: string; readonly [MULTIERROR_SYMBOL] = true; readonly errors: readonly Error[]; constructor(errors: Error[]); toJSON(): Record; } //# sourceMappingURL=verror.d.ts.map