import { ErrorStatus, ErrorStatuses, Failure, StatusError } from './status.js'; import { ErrorCode, ErrorOptions, ErrorTags, StandardError, TaggedErrorCode } from './types.js'; export { CauseExtractor, collectErrorCodes, errorCauseExtractor, ErrorCodeCollection, ErrorMatch, findError, findErrorCode, findErrorWithCode, setCauseExtractors, statusErrorCauseExtractor, } from './cause.js'; export { errorMessage } from './common.js'; export { CoercedError, errors as defaultErrors, errorCode, errorCodes, ErrorCodesFor, errorFactories, ErrorFactoriesFor, ErrorFactoriesParams, ErrorFactory, isStandardError, mergeErrorCodes, newError, OK_CODE, } from './factories.js'; export { ErrorStatus, ErrorStatuses, Failure, failure, isErrorStatus, isInternalProblem, isServerProblem, isStatusError, OK_STATUS, OkStatus, rethrowWithStatus, StatusError, statusError, StatusErrorFactories, StatusErrorFactory, StatusErrorOptions, statusErrors, statusFromGrpcCode, statusFromHttpCode, StatusMapping, StatusProtocol, statusProtocolCode, StatusProtocolCodes, statusToGrpcCode, statusToHttpCode, } from './status.js'; export { DeepErrorCodes, ErrorCode, ErrorCodes, ErrorOptions, ErrorPrefix, ErrorTags, ErrorTagsFor, HasErrorTags, StandardError, StandardErrorForCode, TaggedErrorCode, } from './types.js'; /** Asserts the input predicate, throwing `ERR_ILLEGAL` if not. */ export declare function assert(pred: unknown, fmt: string, ...args: any[]): asserts pred; /** Asserts that an error matches a predicate. */ export declare function assertCause(pred: unknown, err: unknown): asserts pred; /** Asserts that an error has a given error code. */ export declare function assertErrorCode(code: TaggedErrorCode, err: unknown): asserts err is StandardError; export declare function assertErrorCode(code: ErrorCode | ReadonlySet, err: unknown): asserts err is StandardError; /** Asserts that the argument's `typeof` matches the given name. */ export declare function assertType(name: N, arg: unknown): asserts arg is TypeNames[N]; interface TypeNames { bigint: bigint; boolean: boolean; function: Function; number: number; object: {} | null; string: string; symbol: symbol; undefined: undefined; } /** Throws `ERR_ILLEGAL` when predicates are not met. */ export type StrictChecker = (arg: unknown) => R; /** Extends `StrictChecker` with a convenience method to skip missing values. */ export interface Checker extends StrictChecker { /** * Transforms `null` and `undefined` values into `undefined` rather than * throwing. */ readonly orAbsent: StrictChecker; } export declare function newChecker(expected: string, pred: (arg: unknown) => unknown): Checker; export declare const check: { readonly isString: Checker; readonly isNumber: Checker; readonly isNumeric: Checker; readonly isInteger: Checker; readonly isNonNegativeInteger: Checker; readonly isBoolean: Checker; readonly isObject: Checker; readonly isRecord: Checker<{ [key: string]: unknown; }>; readonly isArray: Checker; readonly isBuffer: Checker>; /** Asserts that the input is not null or undefined and returns it. */ readonly isPresent: (arg: V) => Exclude; }; /** * Extracts the first status error from an error's causal chain. The optional * statuses argument can be used to automatically promote certain error codes to * have a given status. If no match was found, an `UNKNOWN` status error is * returned instead. */ export declare function extractStatusError(root: unknown, statuses?: ErrorStatuses): StatusError; /** * Walks an error's causal chain to find the first status error and returns its * status. If no match is found, returns `UNKNOWN`. */ export declare function deriveStatus(root: unknown): ErrorStatus; /** * Derives the best failure from an error. See `extractStatusError` for * information on how the failure's underlying status error is extracted. If not * status error was present, the root is used. */ export declare function deriveFailure(root: unknown, opts?: { /** * Mapping from error code to status use to automatically wrap errors * matching one of the codes with the corresponding status. */ readonly statuses?: ErrorStatuses; /** * List of functions used to compute the returned failure's annotations. The * input error is the one the failure wil be generated from. */ readonly annotators?: ReadonlyArray<(err: StatusError) => string>; }): Failure; /** Returns `ERR_INTERNAL` with `UNIMPLEMENTED` status. */ export declare function unimplemented(...args: any[]): Error; /** Returns an `ERR_ILLEGAL` error with `value` tag set to the input. */ export declare function absurd(val: never): Error; /** Returns an `ERR_ILLEGAL` error with `value` tag set to the input. */ export declare function unexpected(val: unknown): Error; /** * Returns the `value` tag of an `ERR_ILLEGAL` error. This is typically useful * to inspect errors produced by `unexpected` in tests. */ export declare function illegalErrorValue(err: unknown): unknown | undefined; /** Returns an `ERR_ILLEGAL` error. */ export declare function unreachable(): Error; /** Throws `ERR_ILLEGAL`. */ export declare function fail(opts?: ErrorOptions): never; /** * Validates the input predicate, similar to `assert` but throwing `ERR_INVALID` * with `INVALID_ARGUMENT` status on failure. */ export declare function validate(pred: unknown, fmt: string, ...args: any[]): asserts pred; export declare function validate(pred: unknown, opts: Omit, fmt: string, ...args: any[]): asserts pred; /** * Similar to `assertCause` but does not wrap errors which do not match the * predicate. Non-error instances are still coerced. */ export declare function rethrowUnless(pred: unknown, err: unknown): asserts pred;