@little-nebulae/error 1.1.0 → 1.3.0
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/dist/index.d.ts +52 -9
- package/dist/index.js +66 -8
- package/package.json +16 -11
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Tagged, UnknownRecord } from "type-fest";
|
|
2
2
|
//#region src/types.d.ts
|
|
3
|
-
type BaseErrorMeta =
|
|
3
|
+
type BaseErrorMeta = UnknownRecord | null;
|
|
4
4
|
interface BaseErrorType<TCode extends string, TCause = unknown, TMeta extends BaseErrorMeta = null> extends Error {
|
|
5
5
|
cause: TCause;
|
|
6
6
|
code: TCode;
|
|
@@ -28,12 +28,12 @@ export declare class UnexpectedError<TCause = unknown, TMeta extends BaseErrorMe
|
|
|
28
28
|
readonly code = "UNEXPECTED_ERROR";
|
|
29
29
|
}
|
|
30
30
|
//#endregion
|
|
31
|
-
//#region src/helpers/is
|
|
31
|
+
//#region src/helpers/is/abort-error.d.ts
|
|
32
32
|
export declare const ABORT_ERROR_NAME = "AbortError";
|
|
33
33
|
export type AbortErrorName = typeof ABORT_ERROR_NAME;
|
|
34
34
|
export declare const ABORT_ERROR_CODE = "ABORT_ERR";
|
|
35
35
|
export type AbortErrorCode = typeof ABORT_ERROR_CODE;
|
|
36
|
-
export type AbortError =
|
|
36
|
+
export type AbortError = Tagged<Error, AbortErrorName>;
|
|
37
37
|
export declare function isAbortError(value: unknown): value is AbortError;
|
|
38
38
|
//#endregion
|
|
39
39
|
//#region src/classes/aborted.d.ts
|
|
@@ -47,10 +47,10 @@ export declare class AbortedError<TCause extends AbortedErrorCause, TMeta extend
|
|
|
47
47
|
readonly code = "ABORTED_ERROR";
|
|
48
48
|
}
|
|
49
49
|
//#endregion
|
|
50
|
-
//#region src/helpers/is
|
|
50
|
+
//#region src/helpers/is/timeout-error.d.ts
|
|
51
51
|
export declare const TIMEOUT_ERROR_NAME = "TimeoutError";
|
|
52
52
|
export type TimeoutErrorName = typeof TIMEOUT_ERROR_NAME;
|
|
53
|
-
export type TimeoutError =
|
|
53
|
+
export type TimeoutError = Tagged<DOMException, TimeoutErrorName>;
|
|
54
54
|
export declare function isTimeoutError(value: unknown): value is TimeoutError;
|
|
55
55
|
//#endregion
|
|
56
56
|
//#region src/classes/timed-out.d.ts
|
|
@@ -61,13 +61,56 @@ export declare class TimedOutError<TMeta extends BaseErrorMeta = null> extends B
|
|
|
61
61
|
readonly code = "TIMED_OUT_ERROR";
|
|
62
62
|
}
|
|
63
63
|
//#endregion
|
|
64
|
+
//#region src/helpers/is/internal-error.d.ts
|
|
65
|
+
export declare const INTERNAL_ERROR_NAME = "InternalError";
|
|
66
|
+
export type InternalErrorName = typeof INTERNAL_ERROR_NAME;
|
|
67
|
+
export interface InternalError extends Error {
|
|
68
|
+
name: InternalErrorName;
|
|
69
|
+
}
|
|
70
|
+
export declare function isInternalError(value: unknown): value is InternalError;
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/helpers/is/stack-overflow-error.d.ts
|
|
73
|
+
export type StackOverflowErrorTag = "StackOverflowError";
|
|
74
|
+
export type StackOverflowError = Tagged<RangeError | InternalError, StackOverflowErrorTag>;
|
|
75
|
+
export declare function isStackOverflowError(value: unknown): value is StackOverflowError;
|
|
76
|
+
//#endregion
|
|
77
|
+
//#region src/classes/stack-overflowed.d.ts
|
|
78
|
+
export declare const STACK_OVERFLOWED_ERROR_CODE = "STACK_OVERFLOWED_ERROR";
|
|
79
|
+
export type StackOverflowedErrorCode = typeof STACK_OVERFLOWED_ERROR_CODE;
|
|
80
|
+
export declare class StackOverflowedError<TMeta extends BaseErrorMeta = null> extends BaseError<StackOverflowedErrorCode, StackOverflowError, TMeta> {
|
|
81
|
+
readonly name = "StackOverflowedError";
|
|
82
|
+
readonly code = "STACK_OVERFLOWED_ERROR";
|
|
83
|
+
}
|
|
84
|
+
//#endregion
|
|
85
|
+
//#region src/helpers/is/error.d.ts
|
|
86
|
+
export declare function isError(value: unknown): value is Error;
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region src/helpers/is/range-error.d.ts
|
|
89
|
+
export declare function isRangeError(value: unknown): value is RangeError;
|
|
90
|
+
//#endregion
|
|
91
|
+
//#region src/helpers/is/aggregate-error.d.ts
|
|
92
|
+
export declare function isAggregateError(error: Error): error is AggregateError;
|
|
93
|
+
//#endregion
|
|
94
|
+
//#region src/helpers/is/eval-error.d.ts
|
|
95
|
+
export declare function isEvalError(error: Error): error is EvalError;
|
|
96
|
+
//#endregion
|
|
97
|
+
//#region src/helpers/is/reference-error.d.ts
|
|
98
|
+
export declare function isReferenceError(error: Error): error is ReferenceError;
|
|
99
|
+
//#endregion
|
|
100
|
+
//#region src/helpers/is/syntax-error.d.ts
|
|
101
|
+
export declare function isSyntaxError(error: Error): error is SyntaxError;
|
|
102
|
+
//#endregion
|
|
103
|
+
//#region src/helpers/is/type-error.d.ts
|
|
104
|
+
export declare function isTypeError(error: Error): error is TypeError;
|
|
105
|
+
//#endregion
|
|
106
|
+
//#region src/helpers/is/uri-error.d.ts
|
|
107
|
+
export declare function isUriError(error: Error): error is URIError;
|
|
108
|
+
//#endregion
|
|
64
109
|
//#region src/helpers/compose-error-message.d.ts
|
|
110
|
+
export declare const DEFAULT_FAILURE_REASON = "some unexpected error";
|
|
65
111
|
export declare function composeErrorMessage<TOperation extends string, TReason extends string>({ operation, reason }: {
|
|
66
112
|
operation: TOperation;
|
|
67
113
|
reason: TReason;
|
|
68
114
|
}): `Failed to ${TOperation} due to ${TReason}.`;
|
|
69
115
|
//#endregion
|
|
70
|
-
//#region src/helpers/is-error.d.ts
|
|
71
|
-
export declare function isError(value: unknown): value is Error;
|
|
72
|
-
//#endregion
|
|
73
116
|
export type { BaseErrorMeta, BaseErrorType };
|
package/dist/index.js
CHANGED
|
@@ -28,19 +28,21 @@ var TimedOutError = class extends BaseError {
|
|
|
28
28
|
code = TIMED_OUT_ERROR_CODE;
|
|
29
29
|
};
|
|
30
30
|
//#endregion
|
|
31
|
-
//#region src/
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
//#region src/classes/stack-overflowed.ts
|
|
32
|
+
const STACK_OVERFLOWED_ERROR_CODE = "STACK_OVERFLOWED_ERROR";
|
|
33
|
+
var StackOverflowedError = class extends BaseError {
|
|
34
|
+
name = "StackOverflowedError";
|
|
35
|
+
code = STACK_OVERFLOWED_ERROR_CODE;
|
|
36
|
+
};
|
|
35
37
|
//#endregion
|
|
36
|
-
//#region src/helpers/is
|
|
38
|
+
//#region src/helpers/is/error.ts
|
|
37
39
|
function isError(value) {
|
|
38
40
|
if (Object.hasOwn(Error, "isError") && Error.isError(value)) return true;
|
|
39
41
|
if (value instanceof Error) return true;
|
|
40
42
|
return false;
|
|
41
43
|
}
|
|
42
44
|
//#endregion
|
|
43
|
-
//#region src/helpers/is
|
|
45
|
+
//#region src/helpers/is/abort-error.ts
|
|
44
46
|
const ABORT_ERROR_NAME = "AbortError";
|
|
45
47
|
const ABORT_ERROR_CODE = "ABORT_ERR";
|
|
46
48
|
function isAbortError(value) {
|
|
@@ -51,11 +53,67 @@ function isAbortError(value) {
|
|
|
51
53
|
return false;
|
|
52
54
|
}
|
|
53
55
|
//#endregion
|
|
54
|
-
//#region src/helpers/is
|
|
56
|
+
//#region src/helpers/is/timeout-error.ts
|
|
55
57
|
const TIMEOUT_ERROR_NAME = "TimeoutError";
|
|
56
58
|
function isTimeoutError(value) {
|
|
57
59
|
if (value instanceof DOMException && value.name === "TimeoutError") return true;
|
|
58
60
|
return false;
|
|
59
61
|
}
|
|
60
62
|
//#endregion
|
|
61
|
-
|
|
63
|
+
//#region src/helpers/is/range-error.ts
|
|
64
|
+
function isRangeError(value) {
|
|
65
|
+
if (isError(value) && value.name === RangeError.name) return true;
|
|
66
|
+
if (value instanceof RangeError) return true;
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
//#endregion
|
|
70
|
+
//#region src/helpers/is/internal-error.ts
|
|
71
|
+
const INTERNAL_ERROR_NAME = "InternalError";
|
|
72
|
+
function isInternalError(value) {
|
|
73
|
+
return isError(value) && value.name === "InternalError";
|
|
74
|
+
}
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region src/helpers/is/stack-overflow-error.ts
|
|
77
|
+
function isStackOverflowError(value) {
|
|
78
|
+
if (isRangeError(value) && value.message.includes("call stack size exceeded")) return true;
|
|
79
|
+
if (isInternalError(value) && value.message.includes("too much recursion")) return true;
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
//#endregion
|
|
83
|
+
//#region src/helpers/is/aggregate-error.ts
|
|
84
|
+
function isAggregateError(error) {
|
|
85
|
+
return error.name === AggregateError.name;
|
|
86
|
+
}
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region src/helpers/is/eval-error.ts
|
|
89
|
+
function isEvalError(error) {
|
|
90
|
+
return error.name === EvalError.name;
|
|
91
|
+
}
|
|
92
|
+
//#endregion
|
|
93
|
+
//#region src/helpers/is/reference-error.ts
|
|
94
|
+
function isReferenceError(error) {
|
|
95
|
+
return error.name === ReferenceError.name;
|
|
96
|
+
}
|
|
97
|
+
//#endregion
|
|
98
|
+
//#region src/helpers/is/syntax-error.ts
|
|
99
|
+
function isSyntaxError(error) {
|
|
100
|
+
return error.name === SyntaxError.name;
|
|
101
|
+
}
|
|
102
|
+
//#endregion
|
|
103
|
+
//#region src/helpers/is/type-error.ts
|
|
104
|
+
function isTypeError(error) {
|
|
105
|
+
return error.name === TypeError.name;
|
|
106
|
+
}
|
|
107
|
+
//#endregion
|
|
108
|
+
//#region src/helpers/is/uri-error.ts
|
|
109
|
+
function isUriError(error) {
|
|
110
|
+
return error.name === URIError.name;
|
|
111
|
+
}
|
|
112
|
+
//#endregion
|
|
113
|
+
//#region src/helpers/compose-error-message.ts
|
|
114
|
+
const DEFAULT_FAILURE_REASON = "some unexpected error";
|
|
115
|
+
function composeErrorMessage({ operation, reason }) {
|
|
116
|
+
return `Failed to ${operation} due to ${reason}.`;
|
|
117
|
+
}
|
|
118
|
+
//#endregion
|
|
119
|
+
export { ABORTED_ERROR_CODE, ABORT_ERROR_CODE, ABORT_ERROR_NAME, AbortedError, BaseError, DEFAULT_FAILURE_REASON, INTERNAL_ERROR_NAME, STACK_OVERFLOWED_ERROR_CODE, StackOverflowedError, TIMED_OUT_ERROR_CODE, TIMEOUT_ERROR_NAME, TimedOutError, UNEXPECTED_ERROR_CODE, UnexpectedError, composeErrorMessage, isAbortError, isAggregateError, isError, isEvalError, isInternalError, isRangeError, isReferenceError, isStackOverflowError, isSyntaxError, isTimeoutError, isTypeError, isUriError };
|
package/package.json
CHANGED
|
@@ -1,35 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@little-nebulae/error",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
7
7
|
],
|
|
8
8
|
"type": "module",
|
|
9
|
+
"sideEffects": false,
|
|
9
10
|
"exports": {
|
|
10
11
|
".": "./dist/index.js",
|
|
11
12
|
"./package.json": "./package.json"
|
|
12
13
|
},
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public",
|
|
16
|
+
"tag": "latest"
|
|
17
|
+
},
|
|
13
18
|
"devDependencies": {
|
|
14
19
|
"@arethetypeswrong/core": "0.18.5",
|
|
15
|
-
"@
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"oxlint": "
|
|
19
|
-
"
|
|
20
|
-
"publint": "0.3.24",
|
|
20
|
+
"@types/node": "26.6.4",
|
|
21
|
+
"oxfmt": "0.72.0",
|
|
22
|
+
"oxlint": "1.87.0",
|
|
23
|
+
"oxlint-tsgolint": "7.0.2003",
|
|
24
|
+
"publint": "0.3.25",
|
|
21
25
|
"tsdown": "0.23.0",
|
|
22
|
-
"tsx": "4.23.
|
|
26
|
+
"tsx": "4.23.15",
|
|
27
|
+
"type-fest": "5.10.0",
|
|
23
28
|
"typescript": "7.0.2",
|
|
24
|
-
"vitest": "5.0.
|
|
29
|
+
"vitest": "5.0.3"
|
|
25
30
|
},
|
|
26
31
|
"peerDependencies": {
|
|
27
|
-
"
|
|
32
|
+
"type-fest": "^5.0.0"
|
|
28
33
|
},
|
|
29
34
|
"devEngines": {
|
|
30
35
|
"packageManager": {
|
|
31
36
|
"name": "pnpm",
|
|
32
|
-
"version": "12.
|
|
37
|
+
"version": "12.9.1",
|
|
33
38
|
"onFail": "warn"
|
|
34
39
|
}
|
|
35
40
|
},
|