@xylabs/error 5.0.83 → 5.0.84
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -47,20 +47,28 @@ function assertError(
|
|
|
47
47
|
defaultMessage): undefined;
|
|
48
48
|
```
|
|
49
49
|
|
|
50
|
+
Throws an Error based on the assert configuration when a value fails validation.
|
|
51
|
+
|
|
50
52
|
## Parameters
|
|
51
53
|
|
|
52
54
|
### value
|
|
53
55
|
|
|
54
56
|
`unknown`
|
|
55
57
|
|
|
58
|
+
The value being validated
|
|
59
|
+
|
|
56
60
|
### assert
|
|
57
61
|
|
|
62
|
+
Assertion config controlling the error message
|
|
63
|
+
|
|
58
64
|
[`AssertConfig`](#../type-aliases/AssertConfig) | `undefined`
|
|
59
65
|
|
|
60
66
|
### defaultMessage
|
|
61
67
|
|
|
62
68
|
`string`
|
|
63
69
|
|
|
70
|
+
Fallback message if no custom message is provided
|
|
71
|
+
|
|
64
72
|
## Returns
|
|
65
73
|
|
|
66
74
|
`undefined`
|
|
@@ -75,6 +83,8 @@ function assertError(
|
|
|
75
83
|
function handleError<T>(error, handler): T;
|
|
76
84
|
```
|
|
77
85
|
|
|
86
|
+
Invokes the handler if the value is an Error, otherwise re-throws it.
|
|
87
|
+
|
|
78
88
|
## Type Parameters
|
|
79
89
|
|
|
80
90
|
### T
|
|
@@ -87,14 +97,20 @@ function handleError<T>(error, handler): T;
|
|
|
87
97
|
|
|
88
98
|
`any`
|
|
89
99
|
|
|
100
|
+
The caught value to inspect
|
|
101
|
+
|
|
90
102
|
### handler
|
|
91
103
|
|
|
92
104
|
(`error`) => `T`
|
|
93
105
|
|
|
106
|
+
Callback invoked with the Error if it is one
|
|
107
|
+
|
|
94
108
|
## Returns
|
|
95
109
|
|
|
96
110
|
`T`
|
|
97
111
|
|
|
112
|
+
The handler's return value
|
|
113
|
+
|
|
98
114
|
### <a id="handleErrorAsync"></a>handleErrorAsync
|
|
99
115
|
|
|
100
116
|
[**@xylabs/error**](#../README)
|
|
@@ -105,6 +121,8 @@ function handleError<T>(error, handler): T;
|
|
|
105
121
|
function handleErrorAsync<T>(error, handler): Promise<T>;
|
|
106
122
|
```
|
|
107
123
|
|
|
124
|
+
Async version of handleError. Invokes the async handler if the value is an Error, otherwise re-throws it.
|
|
125
|
+
|
|
108
126
|
## Type Parameters
|
|
109
127
|
|
|
110
128
|
### T
|
|
@@ -117,14 +135,20 @@ function handleErrorAsync<T>(error, handler): Promise<T>;
|
|
|
117
135
|
|
|
118
136
|
`any`
|
|
119
137
|
|
|
138
|
+
The caught value to inspect
|
|
139
|
+
|
|
120
140
|
### handler
|
|
121
141
|
|
|
122
142
|
(`error`) => `Promise`\<`T`\>
|
|
123
143
|
|
|
144
|
+
Async callback invoked with the Error if it is one
|
|
145
|
+
|
|
124
146
|
## Returns
|
|
125
147
|
|
|
126
148
|
`Promise`\<`T`\>
|
|
127
149
|
|
|
150
|
+
The handler's resolved return value
|
|
151
|
+
|
|
128
152
|
### <a id="isError"></a>isError
|
|
129
153
|
|
|
130
154
|
[**@xylabs/error**](#../README)
|
|
@@ -137,6 +161,8 @@ function handleErrorAsync<T>(error, handler): Promise<T>;
|
|
|
137
161
|
function isError(value): value is Error;
|
|
138
162
|
```
|
|
139
163
|
|
|
164
|
+
Type guard that checks whether a value is an Error instance.
|
|
165
|
+
|
|
140
166
|
### Parameters
|
|
141
167
|
|
|
142
168
|
### value
|
|
@@ -153,6 +179,8 @@ function isError(value): value is Error;
|
|
|
153
179
|
function isError<T>(value): value is Extract<T, Error>;
|
|
154
180
|
```
|
|
155
181
|
|
|
182
|
+
Type guard that checks whether a value is an Error instance.
|
|
183
|
+
|
|
156
184
|
### Type Parameters
|
|
157
185
|
|
|
158
186
|
### T
|
|
@@ -181,6 +209,8 @@ function isError<T>(value): value is Extract<T, Error>;
|
|
|
181
209
|
type AssertConfig = string | AssertCallback | boolean;
|
|
182
210
|
```
|
|
183
211
|
|
|
212
|
+
Configuration for assertion behavior: a static message string, a boolean toggle, or a callback.
|
|
213
|
+
|
|
184
214
|
|
|
185
215
|
Part of [sdk-js](https://www.npmjs.com/package/@xyo-network/sdk-js)
|
|
186
216
|
|
package/dist/neutral/assert.d.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
type AssertCallback = (value: unknown, message: string) => string | boolean;
|
|
2
|
+
/** Configuration for assertion behavior: a static message string, a boolean toggle, or a callback. */
|
|
2
3
|
export type AssertConfig = string | AssertCallback | boolean;
|
|
4
|
+
/**
|
|
5
|
+
* Throws an Error based on the assert configuration when a value fails validation.
|
|
6
|
+
* @param value - The value being validated
|
|
7
|
+
* @param assert - Assertion config controlling the error message
|
|
8
|
+
* @param defaultMessage - Fallback message if no custom message is provided
|
|
9
|
+
*/
|
|
3
10
|
export declare const assertError: (value: unknown, assert: AssertConfig | undefined, defaultMessage: string) => undefined;
|
|
4
11
|
export {};
|
|
5
12
|
//# sourceMappingURL=assert.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../../src/assert.ts"],"names":[],"mappings":"AAEA,KAAK,cAAc,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,KAAK,MAAM,GAAG,OAAO,CAAA;AAE3E,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,cAAc,GAAG,OAAO,CAAA;AAE5D,eAAO,MAAM,WAAW,GAAI,OAAO,OAAO,EAAE,QAAQ,YAAY,GAAG,SAAS,EAAE,gBAAgB,MAAM,cAcnG,CAAA"}
|
|
1
|
+
{"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../../src/assert.ts"],"names":[],"mappings":"AAEA,KAAK,cAAc,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,KAAK,MAAM,GAAG,OAAO,CAAA;AAE3E,sGAAsG;AACtG,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,cAAc,GAAG,OAAO,CAAA;AAE5D;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GAAI,OAAO,OAAO,EAAE,QAAQ,YAAY,GAAG,SAAS,EAAE,gBAAgB,MAAM,cAcnG,CAAA"}
|
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Invokes the handler if the value is an Error, otherwise re-throws it.
|
|
3
|
+
* @param error - The caught value to inspect
|
|
4
|
+
* @param handler - Callback invoked with the Error if it is one
|
|
5
|
+
* @returns The handler's return value
|
|
6
|
+
*/
|
|
1
7
|
export declare const handleError: <T>(error: any, handler: (error: Error) => T) => T;
|
|
8
|
+
/**
|
|
9
|
+
* Async version of handleError. Invokes the async handler if the value is an Error, otherwise re-throws it.
|
|
10
|
+
* @param error - The caught value to inspect
|
|
11
|
+
* @param handler - Async callback invoked with the Error if it is one
|
|
12
|
+
* @returns The handler's resolved return value
|
|
13
|
+
*/
|
|
2
14
|
export declare const handleErrorAsync: <T>(error: any, handler: (error: Error) => Promise<T>) => Promise<T>;
|
|
3
15
|
//# sourceMappingURL=handleError.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handleError.d.ts","sourceRoot":"","sources":["../../src/handleError.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"handleError.d.ts","sourceRoot":"","sources":["../../src/handleError.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AAEH,eAAO,MAAM,WAAW,GAAI,CAAC,EAAE,OAAO,GAAG,EAAE,SAAS,CAAC,KAAK,EAAE,KAAK,KAAK,CAAC,MAMtE,CAAA;AAED;;;;;GAKG;AAEH,eAAO,MAAM,gBAAgB,GAAU,CAAC,EAAE,OAAO,GAAG,EAAE,SAAS,CAAC,KAAK,EAAE,KAAK,KAAK,OAAO,CAAC,CAAC,CAAC,eAM1F,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/assert.ts","../../src/handleError.ts","../../src/index.ts"],"sourcesContent":["import { isString, isUndefined } from '@xylabs/typeof'\n\ntype AssertCallback = (value: unknown, message: string) => string | boolean\n\nexport type AssertConfig = string | AssertCallback | boolean\n\nexport const assertError = (value: unknown, assert: AssertConfig | undefined, defaultMessage: string) => {\n if (!isUndefined(assert)) {\n const assertString\n = typeof assert === 'string'\n ? assert\n : typeof assert === 'boolean'\n ? defaultMessage\n : assert(value, defaultMessage)\n if (isString(assertString) || assertString === true) {\n throw new Error(assertString === true ? defaultMessage : assertString)\n }\n }\n // eslint-disable-next-line unicorn/no-useless-undefined\n return undefined\n}\n","import { isError } from '@xylabs/typeof'\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const handleError = <T>(error: any, handler: (error: Error) => T) => {\n if (isError(error)) {\n return handler(error)\n } else {\n throw error\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const handleErrorAsync = async <T>(error: any, handler: (error: Error) => Promise<T>) => {\n if (isError(error)) {\n return await handler(error)\n } else {\n throw error\n }\n}\n","export * from './assert.ts'\nexport * from './handleError.ts'\nexport { isError } from '@xylabs/typeof'\n"],"mappings":";AAAA,SAAS,UAAU,mBAAmB;
|
|
1
|
+
{"version":3,"sources":["../../src/assert.ts","../../src/handleError.ts","../../src/index.ts"],"sourcesContent":["import { isString, isUndefined } from '@xylabs/typeof'\n\ntype AssertCallback = (value: unknown, message: string) => string | boolean\n\n/** Configuration for assertion behavior: a static message string, a boolean toggle, or a callback. */\nexport type AssertConfig = string | AssertCallback | boolean\n\n/**\n * Throws an Error based on the assert configuration when a value fails validation.\n * @param value - The value being validated\n * @param assert - Assertion config controlling the error message\n * @param defaultMessage - Fallback message if no custom message is provided\n */\nexport const assertError = (value: unknown, assert: AssertConfig | undefined, defaultMessage: string) => {\n if (!isUndefined(assert)) {\n const assertString\n = typeof assert === 'string'\n ? assert\n : typeof assert === 'boolean'\n ? defaultMessage\n : assert(value, defaultMessage)\n if (isString(assertString) || assertString === true) {\n throw new Error(assertString === true ? defaultMessage : assertString)\n }\n }\n // eslint-disable-next-line unicorn/no-useless-undefined\n return undefined\n}\n","import { isError } from '@xylabs/typeof'\n\n/**\n * Invokes the handler if the value is an Error, otherwise re-throws it.\n * @param error - The caught value to inspect\n * @param handler - Callback invoked with the Error if it is one\n * @returns The handler's return value\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const handleError = <T>(error: any, handler: (error: Error) => T) => {\n if (isError(error)) {\n return handler(error)\n } else {\n throw error\n }\n}\n\n/**\n * Async version of handleError. Invokes the async handler if the value is an Error, otherwise re-throws it.\n * @param error - The caught value to inspect\n * @param handler - Async callback invoked with the Error if it is one\n * @returns The handler's resolved return value\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const handleErrorAsync = async <T>(error: any, handler: (error: Error) => Promise<T>) => {\n if (isError(error)) {\n return await handler(error)\n } else {\n throw error\n }\n}\n","export * from './assert.ts'\nexport * from './handleError.ts'\nexport { isError } from '@xylabs/typeof'\n"],"mappings":";AAAA,SAAS,UAAU,mBAAmB;AAa/B,IAAM,cAAc,CAAC,OAAgB,QAAkC,mBAA2B;AACvG,MAAI,CAAC,YAAY,MAAM,GAAG;AACxB,UAAM,eACF,OAAO,WAAW,WAChB,SACA,OAAO,WAAW,YAChB,iBACA,OAAO,OAAO,cAAc;AACpC,QAAI,SAAS,YAAY,KAAK,iBAAiB,MAAM;AACnD,YAAM,IAAI,MAAM,iBAAiB,OAAO,iBAAiB,YAAY;AAAA,IACvE;AAAA,EACF;AAEA,SAAO;AACT;;;AC3BA,SAAS,eAAe;AASjB,IAAM,cAAc,CAAI,OAAY,YAAiC;AAC1E,MAAI,QAAQ,KAAK,GAAG;AAClB,WAAO,QAAQ,KAAK;AAAA,EACtB,OAAO;AACL,UAAM;AAAA,EACR;AACF;AASO,IAAM,mBAAmB,OAAU,OAAY,YAA0C;AAC9F,MAAI,QAAQ,KAAK,GAAG;AAClB,WAAO,MAAM,QAAQ,KAAK;AAAA,EAC5B,OAAO;AACL,UAAM;AAAA,EACR;AACF;;;AC5BA,SAAS,WAAAA,gBAAe;","names":["isError"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xylabs/error",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.84",
|
|
4
4
|
"description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"error",
|
|
@@ -42,11 +42,11 @@
|
|
|
42
42
|
"!**/*.test.*"
|
|
43
43
|
],
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@xylabs/typeof": "~5.0.
|
|
45
|
+
"@xylabs/typeof": "~5.0.84"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@xylabs/ts-scripts-yarn3": "~7.4.
|
|
49
|
-
"@xylabs/tsconfig": "~7.4.
|
|
48
|
+
"@xylabs/ts-scripts-yarn3": "~7.4.13",
|
|
49
|
+
"@xylabs/tsconfig": "~7.4.13",
|
|
50
50
|
"typescript": "~5.9.3",
|
|
51
51
|
"vitest": "^4.0.18"
|
|
52
52
|
},
|