Skip to content

Commit 4076f44

Browse files
committed
imp: Updated exceptions handling with new Web standards.
1 parent 54735e3 commit 4076f44

File tree

8 files changed

+285
-286
lines changed

8 files changed

+285
-286
lines changed

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@byloth/core",
3-
"version": "2.2.1",
3+
"version": "2.2.2",
44
"description": "An unopinionated collection of useful functions and classes that I use widely in all my projects. 🔧",
55
"keywords": [
66
"Core",
@@ -61,14 +61,14 @@
6161
},
6262
"devDependencies": {
6363
"@byloth/eslint-config-typescript": "^3.2.2",
64-
"@eslint/compat": "^1.4.1",
65-
"@types/node": "^22.19.0",
66-
"@vitest/coverage-v8": "^4.0.8",
64+
"@eslint/compat": "^2.0.0",
65+
"@types/node": "^22.19.1",
66+
"@vitest/coverage-v8": "^4.0.12",
6767
"eslint": "^9.39.1",
6868
"husky": "^9.1.7",
69-
"jsdom": "^27.1.0",
69+
"jsdom": "^27.2.0",
7070
"typescript": "^5.9.3",
71-
"vite": "^7.2.2",
72-
"vitest": "^4.0.8"
71+
"vite": "^7.2.4",
72+
"vitest": "^4.0.12"
7373
}
7474
}

pnpm-lock.yaml

Lines changed: 268 additions & 257 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const VERSION = "2.2.1";
1+
export const VERSION = "2.2.2";
22

33
export type { Constructor, Interval, Timeout, ValueOf } from "./core/types.js";
44

src/models/exceptions/core.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
* // Uncaught Exception: The game saves may be corrupted. Try to restart the game.
1717
* // at /src/game/index.ts:37:15
1818
* // at /src/main.ts:23:17
19-
* //
20-
* // Caused by SyntaxError: Unexpected end of JSON input
19+
* // Caused by: SyntaxError: Unexpected end of JSON input
2120
* // at /src/models/saves.ts:47:17
2221
* // at /src/game/index.ts:12:9
2322
* // at /src/main.ts:23:17
@@ -59,6 +58,7 @@ export default class Exception extends Error
5958
const exc = new Exception(error.message);
6059

6160
exc.stack = error.stack;
61+
exc.cause = error.cause;
6262
exc.name = error.name;
6363

6464
return exc;
@@ -89,18 +89,6 @@ export default class Exception extends Error
8989

9090
this.cause = cause;
9191
this.name = name;
92-
93-
if (cause)
94-
{
95-
if (cause instanceof Error)
96-
{
97-
this.stack += `\n\nCaused by ${cause.stack}`;
98-
}
99-
else
100-
{
101-
this.stack += `\n\nCaused by ${cause}`;
102-
}
103-
}
10492
}
10593

10694
public readonly [Symbol.toStringTag]: string = "Exception";

src/models/iterators/smart-async-iterator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1066,7 +1066,7 @@ export default class SmartAsyncIterator<T, R = void, N = undefined> implements A
10661066
* {
10671067
* try
10681068
* {
1069-
* if (value > 5) { throw new Error("The index is too high."); }
1069+
* if (value > 5) { throw new Exception("The index is too high."); }
10701070
*
10711071
* console.log(value); // 1, 2, 3, 4, 5
10721072
* }

src/models/iterators/smart-iterator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,7 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
939939
* {
940940
* try
941941
* {
942-
* if (value > 5) { throw new Error("The index is too high."); }
942+
* if (value > 5) { throw new Exception("The index is too high."); }
943943
*
944944
* console.log(value); // 1, 2, 3, 4, 5
945945
* }

src/models/promises/smart-promise.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,10 @@ export default class SmartPromise<T = void> implements Promise<T>
261261
* ```ts
262262
* const promise = new SmartPromise((resolve, reject) =>
263263
* {
264-
* setTimeout(() => reject(new Error("An unknown error occurred.")), 1_000);
264+
* setTimeout(() => reject(new Exception("An unknown error occurred.")), 1_000);
265265
* });
266266
*
267-
* promise.catch(); // Uncaught Error: An unknown error occurred.
267+
* promise.catch(); // "Uncaught Exception: An unknown error occurred."
268268
* ```
269269
*
270270
* ---
@@ -288,10 +288,10 @@ export default class SmartPromise<T = void> implements Promise<T>
288288
* ```ts
289289
* const promise = new SmartPromise((resolve, reject) =>
290290
* {
291-
* setTimeout(() => reject(new Error("An unknown error occurred.")), 1_000);
291+
* setTimeout(() => reject(new Exception("An unknown error occurred.")), 1_000);
292292
* });
293293
*
294-
* promise.catch((reason) => console.error(reason)); // "Error: An unknown error occurred."
294+
* promise.catch((reason) => console.error(reason)); // "Uncaught Exception: An unknown error occurred."
295295
* ```
296296
*
297297
* ---

src/models/promises/timed-promise.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import type { MaybePromise, PromiseExecutor } from "./types.js";
2121
*
2222
* promise
2323
* .then((result) => console.log(result)) // "Hello, World!"
24-
* .catch((error) => console.error(error)); // TimeoutException: The operation has timed out.
24+
* .catch((error) => console.error(error)); // "Uncaught TimeoutException: The operation has timed out."
2525
* ```
2626
*
2727
* ---

0 commit comments

Comments
 (0)