import { DeepErrorCodes, ErrorCode, ErrorOptions, ErrorPrefix, ErrorTags, HasErrorTags, StandardError, StandardErrorForCode, TaggedErrorCode } from './types.js'; /** Returns whether the argument is a standard error. */ export declare function isStandardError(arg: unknown, code: TaggedErrorCode): arg is StandardError; export declare function isStandardError(arg: unknown, code?: ErrorCode | ReadonlySet): arg is StandardError; /** Standard success code to use as counterpart to error codes. */ export declare const OK_CODE = "OK"; /** * Returns an error's code if it is a standard error and `undefined` otherwise. */ export declare function errorCode(err: unknown): ErrorCode | undefined; /** * Constructs a new standard error directly from options. In general prefer * using error factories. This can be useful when recreating errors from another * system (for example to translate remote gRPC errors into local standard * ones). This function will throw if `code` is not a valid error code. */ export declare function newError(name: string, code: ErrorCode | string, opts: ErrorOptions & HasErrorTags): StandardError; export declare function newError(name: string, code: ErrorCode | string, opts?: ErrorOptions): StandardError; /** Combines error codes into a single object. */ export declare function mergeErrorCodes(obj: O): DeepErrorCodes; /** * Generates an object containing error factory methods for each of the input * codes. This is particularly useful to concisely generate strongly-typed error * creation methods and tagged codes. */ export declare function errorFactories

(params: ErrorFactoriesParams): [ErrorFactoriesFor, ErrorCodesFor]; export interface ErrorFactoriesParams

{ readonly definitions: O; /** Custom prefix for all defined error codes. The default is `ERR_`. */ readonly prefix?: P; /** * Custom error name. The default is inferred from the prefix if present. For * example `ERR_FOO_BAR_` would yield name `FooBarError`. */ readonly name?: string; /** Omit stack for all defined errors. */ readonly omitStack?: boolean; } export type ErrorFactoriesFor = { readonly [K in keyof O]: O[K] extends (...args: infer A) => StandardError | (ErrorOptions & HasErrorTags) ? (...args: A) => StandardError : O[K] extends (...args: infer A) => ErrorOptions ? (...args: A) => StandardError : O[K] extends string ? () => StandardError : O[K] extends ErrorOptions ? ErrorFactory : never; }; export interface ErrorFactory { (opts?: ErrorOptions): StandardError; (opts: ErrorOptions & HasErrorTags): StandardError; } export type ErrorCodesFor = { readonly [K in keyof O & string as Capitalize]: O[K] extends (...args: any[]) => StandardError | (ErrorOptions & HasErrorTags) ? TaggedErrorCode : ErrorCode; } & ReadonlySet; /** Standard error factories. */ export declare const errors: ErrorFactoriesFor<{ /** Generic internal error. */ internal: { message: string; }; /** Generic illegal state error, used for assertions in particular. */ illegal: { message: string; }; /** Generic invalid argument error. */ invalid: { message: string; }; /** * Coerces non standard errors into one. The original value is available via * its `cause` and its message, if any, as top-level message. If the input * is already a standard error, it is returned unchanged. */ coerced: (err: unknown) => StandardError | { message: string | undefined; cause: unknown; stackFrom: boolean; }; }>, errorCodes: ErrorCodesFor<{ /** Generic internal error. */ internal: { message: string; }; /** Generic illegal state error, used for assertions in particular. */ illegal: { message: string; }; /** Generic invalid argument error. */ invalid: { message: string; }; /** * Coerces non standard errors into one. The original value is available via * its `cause` and its message, if any, as top-level message. If the input * is already a standard error, it is returned unchanged. */ coerced: (err: unknown) => StandardError | { message: string | undefined; cause: unknown; stackFrom: boolean; }; }>; /** Convenience type for standard errors with code `ERR_COERCED`. */ export type CoercedError = StandardErrorForCode;