@little-nebulae/error 1.0.1 → 1.2.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 +63 -4
- package/dist/index.js +66 -6
- package/package.json +17 -9
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { Tagged, UnknownRecord } from "type-fest";
|
|
1
2
|
//#region src/types.d.ts
|
|
2
|
-
type BaseErrorMeta =
|
|
3
|
+
type BaseErrorMeta = UnknownRecord | null;
|
|
3
4
|
interface BaseErrorType<TCode extends string, TCause = unknown, TMeta extends BaseErrorMeta = null> extends Error {
|
|
4
5
|
cause: TCause;
|
|
5
6
|
code: TCode;
|
|
@@ -27,13 +28,71 @@ export declare class UnexpectedError<TCause = unknown, TMeta extends BaseErrorMe
|
|
|
27
28
|
readonly code = "UNEXPECTED_ERROR";
|
|
28
29
|
}
|
|
29
30
|
//#endregion
|
|
31
|
+
//#region src/helpers/is/abort-error.d.ts
|
|
32
|
+
export declare const ABORT_ERROR_NAME = "AbortError";
|
|
33
|
+
export type AbortErrorName = typeof ABORT_ERROR_NAME;
|
|
34
|
+
export declare const ABORT_ERROR_CODE = "ABORT_ERR";
|
|
35
|
+
export type AbortErrorCode = typeof ABORT_ERROR_CODE;
|
|
36
|
+
export type AbortError = Tagged<Error, AbortErrorName>;
|
|
37
|
+
export declare function isAbortError(value: unknown): value is AbortError;
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/classes/aborted.d.ts
|
|
40
|
+
export declare const ABORTED_ERROR_CODE = "ABORTED_ERROR";
|
|
41
|
+
export type AbortedErrorCode = typeof ABORTED_ERROR_CODE;
|
|
42
|
+
export type AbortedErrorCause = AbortError | {
|
|
43
|
+
reason: AbortSignal["reason"];
|
|
44
|
+
};
|
|
45
|
+
export declare class AbortedError<TCause extends AbortedErrorCause, TMeta extends BaseErrorMeta = null> extends BaseError<AbortedErrorCode, TCause, TMeta> {
|
|
46
|
+
readonly name = "AbortedError";
|
|
47
|
+
readonly code = "ABORTED_ERROR";
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region src/helpers/is/timeout-error.d.ts
|
|
51
|
+
export declare const TIMEOUT_ERROR_NAME = "TimeoutError";
|
|
52
|
+
export type TimeoutErrorName = typeof TIMEOUT_ERROR_NAME;
|
|
53
|
+
export type TimeoutError = Tagged<DOMException, TimeoutErrorName>;
|
|
54
|
+
export declare function isTimeoutError(value: unknown): value is TimeoutError;
|
|
55
|
+
//#endregion
|
|
56
|
+
//#region src/classes/timed-out.d.ts
|
|
57
|
+
export declare const TIMED_OUT_ERROR_CODE = "TIMED_OUT_ERROR";
|
|
58
|
+
export type TimedOutErrorCode = typeof TIMED_OUT_ERROR_CODE;
|
|
59
|
+
export declare class TimedOutError<TMeta extends BaseErrorMeta = null> extends BaseError<TimedOutErrorCode, TimeoutError, TMeta> {
|
|
60
|
+
readonly name = "TimedOutError";
|
|
61
|
+
readonly code = "TIMED_OUT_ERROR";
|
|
62
|
+
}
|
|
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
|
|
30
91
|
//#region src/helpers/compose-error-message.d.ts
|
|
92
|
+
export declare const DEFAULT_FAILURE_REASON = "some unexpected error";
|
|
31
93
|
export declare function composeErrorMessage<TOperation extends string, TReason extends string>({ operation, reason }: {
|
|
32
94
|
operation: TOperation;
|
|
33
95
|
reason: TReason;
|
|
34
96
|
}): `Failed to ${TOperation} due to ${TReason}.`;
|
|
35
97
|
//#endregion
|
|
36
|
-
//#region src/helpers/is-error.d.ts
|
|
37
|
-
export declare function isError(value: unknown): value is Error;
|
|
38
|
-
//#endregion
|
|
39
98
|
export type { BaseErrorMeta, BaseErrorType };
|
package/dist/index.js
CHANGED
|
@@ -14,16 +14,76 @@ var UnexpectedError = class extends BaseError {
|
|
|
14
14
|
code = UNEXPECTED_ERROR_CODE;
|
|
15
15
|
};
|
|
16
16
|
//#endregion
|
|
17
|
-
//#region src/
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
//#region src/classes/aborted.ts
|
|
18
|
+
const ABORTED_ERROR_CODE = "ABORTED_ERROR";
|
|
19
|
+
var AbortedError = class extends BaseError {
|
|
20
|
+
name = "AbortedError";
|
|
21
|
+
code = ABORTED_ERROR_CODE;
|
|
22
|
+
};
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region src/classes/timed-out.ts
|
|
25
|
+
const TIMED_OUT_ERROR_CODE = "TIMED_OUT_ERROR";
|
|
26
|
+
var TimedOutError = class extends BaseError {
|
|
27
|
+
name = "TimedOutError";
|
|
28
|
+
code = TIMED_OUT_ERROR_CODE;
|
|
29
|
+
};
|
|
21
30
|
//#endregion
|
|
22
|
-
//#region src/
|
|
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
|
+
};
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region src/helpers/is/error.ts
|
|
23
39
|
function isError(value) {
|
|
24
40
|
if (Object.hasOwn(Error, "isError") && Error.isError(value)) return true;
|
|
25
41
|
if (value instanceof Error) return true;
|
|
26
42
|
return false;
|
|
27
43
|
}
|
|
28
44
|
//#endregion
|
|
29
|
-
|
|
45
|
+
//#region src/helpers/is/abort-error.ts
|
|
46
|
+
const ABORT_ERROR_NAME = "AbortError";
|
|
47
|
+
const ABORT_ERROR_CODE = "ABORT_ERR";
|
|
48
|
+
function isAbortError(value) {
|
|
49
|
+
if (isError(value)) {
|
|
50
|
+
if (value.name === "AbortError") return true;
|
|
51
|
+
if (Object.hasOwn(value, "code") && value.code === "ABORT_ERR") return true;
|
|
52
|
+
}
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
//#endregion
|
|
56
|
+
//#region src/helpers/is/timeout-error.ts
|
|
57
|
+
const TIMEOUT_ERROR_NAME = "TimeoutError";
|
|
58
|
+
function isTimeoutError(value) {
|
|
59
|
+
if (value instanceof DOMException && value.name === "TimeoutError") return true;
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
//#endregion
|
|
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/compose-error-message.ts
|
|
84
|
+
const DEFAULT_FAILURE_REASON = "some unexpected error";
|
|
85
|
+
function composeErrorMessage({ operation, reason }) {
|
|
86
|
+
return `Failed to ${operation} due to ${reason}.`;
|
|
87
|
+
}
|
|
88
|
+
//#endregion
|
|
89
|
+
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, isError, isInternalError, isRangeError, isStackOverflowError, isTimeoutError };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@little-nebulae/error",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -10,22 +10,30 @@
|
|
|
10
10
|
".": "./dist/index.js",
|
|
11
11
|
"./package.json": "./package.json"
|
|
12
12
|
},
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public",
|
|
15
|
+
"tag": "latest"
|
|
16
|
+
},
|
|
13
17
|
"devDependencies": {
|
|
14
18
|
"@arethetypeswrong/core": "0.18.5",
|
|
15
|
-
"@types/node": "26.4
|
|
16
|
-
"oxfmt": "0.
|
|
17
|
-
"oxlint": "1.
|
|
18
|
-
"oxlint-tsgolint": "7.0.
|
|
19
|
-
"publint": "0.3.
|
|
19
|
+
"@types/node": "26.6.4",
|
|
20
|
+
"oxfmt": "0.71.0",
|
|
21
|
+
"oxlint": "1.86.0",
|
|
22
|
+
"oxlint-tsgolint": "7.0.2003",
|
|
23
|
+
"publint": "0.3.25",
|
|
20
24
|
"tsdown": "0.23.0",
|
|
21
|
-
"tsx": "4.23.
|
|
25
|
+
"tsx": "4.23.15",
|
|
26
|
+
"type-fest": "5.10.0",
|
|
22
27
|
"typescript": "7.0.2",
|
|
23
|
-
"vitest": "5.0.
|
|
28
|
+
"vitest": "5.0.3"
|
|
29
|
+
},
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"type-fest": "^5.0.0"
|
|
24
32
|
},
|
|
25
33
|
"devEngines": {
|
|
26
34
|
"packageManager": {
|
|
27
35
|
"name": "pnpm",
|
|
28
|
-
"version": "12.
|
|
36
|
+
"version": "12.9.1",
|
|
29
37
|
"onFail": "warn"
|
|
30
38
|
}
|
|
31
39
|
},
|