@xylabs/error


Base functionality used throughout XY Labs TypeScript/JavaScript libraries
Reference
@xylabs/error
Type Aliases
| AssertConfig | Configuration for assertion behavior: a static message string, a boolean toggle, or a callback. |
Functions
| assertError | Throws an Error based on the assert configuration when a value fails validation. |
| handleError | Invokes the handler if the value is an Error, otherwise re-throws it. |
| handleErrorAsync | Async version of handleError. Invokes the async handler if the value is an Error, otherwise re-throws it. |
| isError | Type guard that checks whether a value is an Error instance. |
functions
assertError
@xylabs/error
function assertError(
value: unknown,
assert: AssertConfig | undefined,
defaultMessage: string): undefined;
Throws an Error based on the assert configuration when a value fails validation.
Parameters
value | unknown | The value being validated |
assert | AssertConfig | undefined | Assertion config controlling the error message |
defaultMessage | string | Fallback message if no custom message is provided |
Returns
undefined
handleError
@xylabs/error
function handleError<T>(error: any, handler: (error: Error) => T): T;
Invokes the handler if the value is an Error, otherwise re-throws it.
Type Parameters
Parameters
error | any | The caught value to inspect |
handler | (error: Error) => T | Callback invoked with the Error if it is one |
Returns
T
The handler's return value
handleErrorAsync
@xylabs/error
function handleErrorAsync<T>(error: any, handler: (error: Error) => Promise<T>): Promise<T>;
Async version of handleError. Invokes the async handler if the value is an Error, otherwise re-throws it.
Type Parameters
Parameters
error | any | The caught value to inspect |
handler | (error: Error) => Promise<T> | Async callback invoked with the Error if it is one |
Returns
Promise<T>
The handler's resolved return value
isError
@xylabs/error
Call Signature
function isError(value: unknown): value is Error;
Type guard that checks whether a value is an Error instance.
Parameters
Returns
value is Error
Call Signature
function isError<T>(value: T): value is Extract<T, Error>;
Type guard that checks whether a value is an Error instance.
Type Parameters
Parameters
Returns
value is Extract<T, Error>
type-aliases
AssertConfig
@xylabs/error
type AssertConfig = string | AssertCallback | boolean;
Configuration for assertion behavior: a static message string, a boolean toggle, or a callback.
Part of sdk-js
Maintainers
License
See the LICENSE file for license details
Credits
Made with 🔥 and ❄️ by XYLabs