import { z } from 'zod'; declare const ERROR_DISCRIMINATOR = "sy_x_error"; /** * @returns general function that returns true if an error matches a set of * abstracted criteria */ export type Matcher = (e: unknown) => boolean; /** an error type that can match against other errors. */ export interface Matchable { /** * @returns true if the provided error matches the matchable. */ matches: Matcher; } /** * An error that has a network-portable type, allowing it to be encoded/decoded into * a JSON representation. Also allows for simpler matching using @method matches instead of using * instanceof, which has a number of caveats. */ export interface Typed extends Error, Matchable { discriminator: typeof ERROR_DISCRIMINATOR; /** * Returns a unique type identifier for the error. The errors package uses this to * determine the correct decoder to use when encoding/decoding errors. */ type: string; } /** * a class that, when constructed, implements the TypedError interface. Also provides * utilities for matching and creating subclasses. */ export interface TypedClass extends Matchable { /** * constructs a new TypedError. Identical to the Error constructor. * @param message - the error message. * @param options - the error options. * @returns a new TypedError. */ new (message?: string, options?: ErrorOptions): Typed; /** * the type of the error. */ TYPE: string; /** * creates a new subclass of the error that extends its type. So if the type of this * class is `dog` and subType is `labrador`, the type of the new class will be * `dog.labrador`. * @param subType - the type of the new error. * @returns a new TypedErrorClass. */ sub: (subType: string) => TypedClass; } /** * Creates a new class definition that implements the TypedErrorClass interface. * @param type - the type of the error. * @returns a new TypedErrorClass. * @example * ```ts * class MyError extends createTypedError("my_error") {} * ``` */ export declare const createTyped: (type: string) => TypedClass; /** * Function that decodes an encoded error payload back into an error object * @param encoded - The encoded error payload to decode * @returns The decoded error object or null if the decoder cannot handle this error * type */ export type Decoder = (encoded: Payload) => Error | null; /** * Function that encodes a typed error into a network-portable payload * @param error - The typed error to encode * @returns The encoded error payload or null if the encoder cannot handle this error type */ export type Encoder = (error: Typed) => Payload | null; /** * Checks if an unknown value is a TypedError * @param error - The value to check * @returns True if the value is a TypedError, false otherwise */ export declare const isTyped: (error: unknown) => error is Typed; /** * Coerces an arbitrary thrown value into an `Error` so it can be re-thrown without * tripping `@typescript-eslint/only-throw-error` and so callers can rely on a uniform * `Error` shape. The original value is preserved on `Error.cause` for stack-trace * continuity. * * - If `value` is already an `Error`, it is returned unchanged. * - Otherwise the message is derived from `JSON.stringify(value)` when possible (which * carries more detail for plain objects), falling back to `String(value)` for * circular structures, BigInts, or anything else that fails to serialize. */ export declare const fromUnknown: (value: unknown) => Error; /** Constant representing an unknown error type */ export declare const UNKNOWN = "unknown"; /** Constant representing no error (null) */ export declare const NONE = "nil"; /** * provides custom encoding/decoding mechanisms for specific error * categories. */ interface Provider { /** * Encodes an error into a primitive payload that can be sent over the network or stored * on disk. * @param error - The error to encode. * @returns The encoded error. */ encode: Encoder; /** * Decodes an error from a primitive payload that can be sent over the network or stored * on disk. * @param payload - The encoded error. * @returns The decoded error. */ decode: Decoder; } /** * Registers a custom error type with the error registry, which allows it to be * encoded/decoded and sent over the network. * * @param type - A unique string identifier for the error type. * @param encode - A function that encodes the error into a string. * @param decode - A function that decodes the error from a string. */ export declare const register: ({ encode, decode }: Provider) => void; /** * Encodes an error into a primitive payload that can be sent over the network or stored * on disk. * @param error - The error to encode. * @returns The encoded error. */ export declare const encode: (error: unknown) => Payload; /** * Decodes an error payload into an exception. If a custom decoder can be found * for the error type, it will be used. Otherwise, a generic Error containing * the error data is returned. * * @param payload - The encoded error payload. * @returns The decoded error. */ export declare const decode: (payload?: Payload | null) => Error | null; declare const Unknown_base: TypedClass; /** * Generic error for representing unknown errors */ export declare class Unknown extends Unknown_base { } /** Zod schema for validating error payloads. `name` and `stack` are TypeScript-only * fields; Go and Python don't populate them. They're carried opaquely across the wire * and re-applied to the reconstructed error on decode, which keeps the original error * name (e.g. "TypeError") and stack trace alive across worker / network boundaries. */ export declare const payloadZ: z.ZodObject<{ type: z.ZodString; data: z.ZodString; name: z.ZodOptional; stack: z.ZodOptional; }, z.core.$strip>; /** Network-portable representation of an error */ export type Payload = z.infer; declare const Canceled_base: TypedClass; /** Error for representing the cancellation of an operation */ export declare class Canceled extends Canceled_base { } declare const NotImplemented_base: TypedClass; /** Error for representing a method that is not implemented */ export declare class NotImplemented extends NotImplemented_base { } export {}; //# sourceMappingURL=errors.d.ts.map