tryless
Version:
Type-safe error handling for TypeScript without try-catch hell
43 lines • 1.45 kB
TypeScript
import type { IUnknownOkErr } from './result/types';
/**
* Error thrown when attempting to unwrap a Result that contains an error,
* or when expecting a specific error type that doesn't match.
*
* This error provides detailed stack traces showing both where the unwrap
* was attempted and where the original error result was created.
*
* @example
* ```ts
* import { err } from 'tryless';
*
* const result = err('NotFound', 'User not found');
* try {
* const data = result.unwrap(); // throws UnwrapError
* } catch (error) {
* console.log(error.name); // 'UnwrapError'
* console.log(error.error); // 'NotFound'
* console.log(error.reason); // 'User not found'
* }
* ```
*/
export declare class UnwrapError extends Error {
/**
* The error identifier from the failed result.
*/
error: string;
/**
* Additional information about why the error occurred.
*/
reason?: unknown;
resultStack?: string;
/**
* Creates a new UnwrapError instance.
*
* @param result - The result that failed to unwrap
* @param caller - The function that attempted the unwrap (for stack trace)
* @param customMessage - Optional custom error message
* @param customError - Optional custom error identifier
*/
constructor(result: IUnknownOkErr, caller: (...args: unknown[]) => unknown, customMessage?: string, customError?: string);
}
//# sourceMappingURL=unwrap-error.d.ts.map