@little-nebulae/error 1.0.0 → 1.1.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 +34 -0
- package/dist/index.js +33 -1
- package/package.json +8 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Branded } from "@little-nebulae/type-utils";
|
|
1
2
|
//#region src/types.d.ts
|
|
2
3
|
type BaseErrorMeta = Record<string, unknown> | null;
|
|
3
4
|
interface BaseErrorType<TCode extends string, TCause = unknown, TMeta extends BaseErrorMeta = null> extends Error {
|
|
@@ -27,6 +28,39 @@ 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 = Branded<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 = Branded<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
|
|
30
64
|
//#region src/helpers/compose-error-message.d.ts
|
|
31
65
|
export declare function composeErrorMessage<TOperation extends string, TReason extends string>({ operation, reason }: {
|
|
32
66
|
operation: TOperation;
|
package/dist/index.js
CHANGED
|
@@ -14,6 +14,20 @@ var UnexpectedError = class extends BaseError {
|
|
|
14
14
|
code = UNEXPECTED_ERROR_CODE;
|
|
15
15
|
};
|
|
16
16
|
//#endregion
|
|
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
|
+
};
|
|
30
|
+
//#endregion
|
|
17
31
|
//#region src/helpers/compose-error-message.ts
|
|
18
32
|
function composeErrorMessage({ operation, reason }) {
|
|
19
33
|
return `Failed to ${operation} due to ${reason}.`;
|
|
@@ -26,4 +40,22 @@ function isError(value) {
|
|
|
26
40
|
return false;
|
|
27
41
|
}
|
|
28
42
|
//#endregion
|
|
29
|
-
|
|
43
|
+
//#region src/helpers/is-abort-error.ts
|
|
44
|
+
const ABORT_ERROR_NAME = "AbortError";
|
|
45
|
+
const ABORT_ERROR_CODE = "ABORT_ERR";
|
|
46
|
+
function isAbortError(value) {
|
|
47
|
+
if (isError(value)) {
|
|
48
|
+
if (value.name === "AbortError") return true;
|
|
49
|
+
if (Object.hasOwn(value, "code") && value.code === "ABORT_ERR") return true;
|
|
50
|
+
}
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region src/helpers/is-timeout-error.ts
|
|
55
|
+
const TIMEOUT_ERROR_NAME = "TimeoutError";
|
|
56
|
+
function isTimeoutError(value) {
|
|
57
|
+
if (value instanceof DOMException && value.name === "TimeoutError") return true;
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
//#endregion
|
|
61
|
+
export { ABORTED_ERROR_CODE, ABORT_ERROR_CODE, ABORT_ERROR_NAME, AbortedError, BaseError, TIMED_OUT_ERROR_CODE, TIMEOUT_ERROR_NAME, TimedOutError, UNEXPECTED_ERROR_CODE, UnexpectedError, composeErrorMessage, isAbortError, isError, isTimeoutError };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@little-nebulae/error",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -12,15 +12,19 @@
|
|
|
12
12
|
},
|
|
13
13
|
"devDependencies": {
|
|
14
14
|
"@arethetypeswrong/core": "0.18.5",
|
|
15
|
-
"@
|
|
15
|
+
"@little-nebulae/type-utils": "1.1.0",
|
|
16
|
+
"@types/node": "26.6.1",
|
|
16
17
|
"oxfmt": "0.68.0",
|
|
17
18
|
"oxlint": "1.83.0",
|
|
18
|
-
"oxlint-tsgolint": "7.0.
|
|
19
|
+
"oxlint-tsgolint": "7.0.2002",
|
|
19
20
|
"publint": "0.3.24",
|
|
20
21
|
"tsdown": "0.23.0",
|
|
21
22
|
"tsx": "4.23.13",
|
|
22
23
|
"typescript": "7.0.2",
|
|
23
|
-
"vitest": "5.0.
|
|
24
|
+
"vitest": "5.0.1"
|
|
25
|
+
},
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"@little-nebulae/type-utils": "^1.1.0"
|
|
24
28
|
},
|
|
25
29
|
"devEngines": {
|
|
26
30
|
"packageManager": {
|