@xylabs/error
Advanced tools
+4
-4
| { | ||
| "name": "@xylabs/error", | ||
| "version": "5.0.84", | ||
| "version": "5.0.86", | ||
| "description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries", | ||
@@ -45,7 +45,7 @@ "keywords": [ | ||
| "dependencies": { | ||
| "@xylabs/typeof": "~5.0.84" | ||
| "@xylabs/typeof": "~5.0.86" | ||
| }, | ||
| "devDependencies": { | ||
| "@xylabs/ts-scripts-yarn3": "~7.4.13", | ||
| "@xylabs/tsconfig": "~7.4.13", | ||
| "@xylabs/ts-scripts-yarn3": "~7.4.16", | ||
| "@xylabs/tsconfig": "~7.4.16", | ||
| "typescript": "~5.9.3", | ||
@@ -52,0 +52,0 @@ "vitest": "^4.0.18" |
+46
-66
@@ -18,2 +18,4 @@ # @xylabs/error | ||
| ## Reference | ||
@@ -27,10 +29,14 @@ | ||
| - [AssertConfig](#type-aliases/AssertConfig) | ||
| | Type Alias | Description | | ||
| | ------ | ------ | | ||
| | [AssertConfig](#type-aliases/AssertConfig) | Configuration for assertion behavior: a static message string, a boolean toggle, or a callback. | | ||
| ## Functions | ||
| - [assertError](#functions/assertError) | ||
| - [handleError](#functions/handleError) | ||
| - [handleErrorAsync](#functions/handleErrorAsync) | ||
| - [isError](#functions/isError) | ||
| | Function | Description | | ||
| | ------ | ------ | | ||
| | [assertError](#functions/assertError) | Throws an Error based on the assert configuration when a value fails validation. | | ||
| | [handleError](#functions/handleError) | Invokes the handler if the value is an Error, otherwise re-throws it. | | ||
| | [handleErrorAsync](#functions/handleErrorAsync) | Async version of handleError. Invokes the async handler if the value is an Error, otherwise re-throws it. | | ||
| | [isError](#functions/isError) | Type guard that checks whether a value is an Error instance. | | ||
@@ -47,5 +53,5 @@ ### functions | ||
| function assertError( | ||
| value, | ||
| assert, | ||
| defaultMessage): undefined; | ||
| value: unknown, | ||
| assert: AssertConfig | undefined, | ||
| defaultMessage: string): undefined; | ||
| ``` | ||
@@ -57,20 +63,8 @@ | ||
| ### value | ||
| | Parameter | Type | Description | | ||
| | ------ | ------ | ------ | | ||
| | `value` | `unknown` | The value being validated | | ||
| | `assert` | [`AssertConfig`](#../type-aliases/AssertConfig) \| `undefined` | Assertion config controlling the error message | | ||
| | `defaultMessage` | `string` | Fallback message if no custom message is provided | | ||
| `unknown` | ||
| The value being validated | ||
| ### assert | ||
| Assertion config controlling the error message | ||
| [`AssertConfig`](#../type-aliases/AssertConfig) | `undefined` | ||
| ### defaultMessage | ||
| `string` | ||
| Fallback message if no custom message is provided | ||
| ## Returns | ||
@@ -87,3 +81,3 @@ | ||
| ```ts | ||
| function handleError<T>(error, handler): T; | ||
| function handleError<T>(error: any, handler: (error: Error) => T): T; | ||
| ``` | ||
@@ -95,20 +89,13 @@ | ||
| ### T | ||
| | Type Parameter | | ||
| | ------ | | ||
| | `T` | | ||
| `T` | ||
| ## Parameters | ||
| ### error | ||
| | Parameter | Type | Description | | ||
| | ------ | ------ | ------ | | ||
| | `error` | `any` | The caught value to inspect | | ||
| | `handler` | (`error`: `Error`) => `T` | Callback invoked with the Error if it is one | | ||
| `any` | ||
| The caught value to inspect | ||
| ### handler | ||
| (`error`) => `T` | ||
| Callback invoked with the Error if it is one | ||
| ## Returns | ||
@@ -127,3 +114,3 @@ | ||
| ```ts | ||
| function handleErrorAsync<T>(error, handler): Promise<T>; | ||
| function handleErrorAsync<T>(error: any, handler: (error: Error) => Promise<T>): Promise<T>; | ||
| ``` | ||
@@ -135,20 +122,13 @@ | ||
| ### T | ||
| | Type Parameter | | ||
| | ------ | | ||
| | `T` | | ||
| `T` | ||
| ## Parameters | ||
| ### error | ||
| | Parameter | Type | Description | | ||
| | ------ | ------ | ------ | | ||
| | `error` | `any` | The caught value to inspect | | ||
| | `handler` | (`error`: `Error`) => `Promise`\<`T`\> | Async callback invoked with the Error if it is one | | ||
| `any` | ||
| The caught value to inspect | ||
| ### handler | ||
| (`error`) => `Promise`\<`T`\> | ||
| Async callback invoked with the Error if it is one | ||
| ## Returns | ||
@@ -169,3 +149,3 @@ | ||
| ```ts | ||
| function isError(value): value is Error; | ||
| function isError(value: unknown): value is Error; | ||
| ``` | ||
@@ -177,6 +157,6 @@ | ||
| ### value | ||
| | Parameter | Type | | ||
| | ------ | ------ | | ||
| | `value` | `unknown` | | ||
| `unknown` | ||
| ### Returns | ||
@@ -189,3 +169,3 @@ | ||
| ```ts | ||
| function isError<T>(value): value is Extract<T, Error>; | ||
| function isError<T>(value: T): value is Extract<T, Error>; | ||
| ``` | ||
@@ -197,12 +177,12 @@ | ||
| ### T | ||
| | Type Parameter | | ||
| | ------ | | ||
| | `T` | | ||
| `T` | ||
| ### Parameters | ||
| ### value | ||
| | Parameter | Type | | ||
| | ------ | ------ | | ||
| | `value` | `T` | | ||
| `T` | ||
| ### Returns | ||
@@ -209,0 +189,0 @@ |
21440
5.16%232
-7.94%Updated