@little-nebulae/error 1.1.0 → 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 CHANGED
@@ -1,6 +1,6 @@
1
- import { Branded } from "@little-nebulae/type-utils";
1
+ import { Tagged, UnknownRecord } from "type-fest";
2
2
  //#region src/types.d.ts
3
- type BaseErrorMeta = Record<string, unknown> | null;
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-abort-error.d.ts
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 = Branded<Error, AbortErrorName>;
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-timeout-error.d.ts
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 = Branded<DOMException, TimeoutErrorName>;
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,38 @@ 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
64
91
  //#region src/helpers/compose-error-message.d.ts
92
+ export declare const DEFAULT_FAILURE_REASON = "some unexpected error";
65
93
  export declare function composeErrorMessage<TOperation extends string, TReason extends string>({ operation, reason }: {
66
94
  operation: TOperation;
67
95
  reason: TReason;
68
96
  }): `Failed to ${TOperation} due to ${TReason}.`;
69
97
  //#endregion
70
- //#region src/helpers/is-error.d.ts
71
- export declare function isError(value: unknown): value is Error;
72
- //#endregion
73
98
  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/helpers/compose-error-message.ts
32
- function composeErrorMessage({ operation, reason }) {
33
- return `Failed to ${operation} due to ${reason}.`;
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-error.ts
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-abort-error.ts
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,37 @@ function isAbortError(value) {
51
53
  return false;
52
54
  }
53
55
  //#endregion
54
- //#region src/helpers/is-timeout-error.ts
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
- 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 };
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.1.0",
3
+ "version": "1.2.0",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "dist"
@@ -10,26 +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
- "@little-nebulae/type-utils": "1.1.0",
16
- "@types/node": "26.6.1",
17
- "oxfmt": "0.68.0",
18
- "oxlint": "1.83.0",
19
- "oxlint-tsgolint": "7.0.2002",
20
- "publint": "0.3.24",
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",
21
24
  "tsdown": "0.23.0",
22
- "tsx": "4.23.13",
25
+ "tsx": "4.23.15",
26
+ "type-fest": "5.10.0",
23
27
  "typescript": "7.0.2",
24
- "vitest": "5.0.1"
28
+ "vitest": "5.0.3"
25
29
  },
26
30
  "peerDependencies": {
27
- "@little-nebulae/type-utils": "^1.1.0"
31
+ "type-fest": "^5.0.0"
28
32
  },
29
33
  "devEngines": {
30
34
  "packageManager": {
31
35
  "name": "pnpm",
32
- "version": "12.4.2",
36
+ "version": "12.9.1",
33
37
  "onFail": "warn"
34
38
  }
35
39
  },