@jskit-ai/kernel 0.1.116 → 0.1.118
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/package.json
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
class KernelError extends Error {
|
|
2
2
|
constructor(message, details = {}) {
|
|
3
|
-
|
|
3
|
+
const normalizedDetails = details && typeof details === "object" ? { ...details } : {};
|
|
4
|
+
const hasCause = Object.prototype.hasOwnProperty.call(normalizedDetails, "cause");
|
|
5
|
+
super(
|
|
6
|
+
String(message || "Kernel error."),
|
|
7
|
+
hasCause ? { cause: normalizedDetails.cause } : undefined
|
|
8
|
+
);
|
|
4
9
|
this.name = this.constructor.name;
|
|
5
|
-
this.details =
|
|
10
|
+
this.details = normalizedDetails;
|
|
6
11
|
}
|
|
7
12
|
}
|
|
8
13
|
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { spawnSync } from "node:child_process";
|
|
3
|
+
import process from "node:process";
|
|
4
|
+
import test from "node:test";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { KernelError } from "./kernelErrors.js";
|
|
7
|
+
|
|
8
|
+
const APPLICATION_PATH = fileURLToPath(new URL("./application.js", import.meta.url));
|
|
9
|
+
|
|
10
|
+
test("KernelError preserves structured details while exposing the standard cause", () => {
|
|
11
|
+
const cause = new Error("underlying failure");
|
|
12
|
+
const error = new KernelError("outer failure", {
|
|
13
|
+
cause,
|
|
14
|
+
providerId: "example.provider"
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
assert.equal(error.cause, cause);
|
|
18
|
+
assert.equal(error.details.cause, cause);
|
|
19
|
+
assert.equal(error.details.providerId, "example.provider");
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test("provider lifecycle failures expose their standard cause through Node error reporting", () => {
|
|
23
|
+
const source = `
|
|
24
|
+
import { Application } from ${JSON.stringify(APPLICATION_PATH)};
|
|
25
|
+
|
|
26
|
+
const app = new Application();
|
|
27
|
+
app.configureProviders([{
|
|
28
|
+
id: "json-rest-api.core",
|
|
29
|
+
async boot() {
|
|
30
|
+
throw new Error('DB_CLIENT is required. Use mysql2 or pg.');
|
|
31
|
+
}
|
|
32
|
+
}]);
|
|
33
|
+
|
|
34
|
+
try {
|
|
35
|
+
await app.bootProviders();
|
|
36
|
+
} catch (error) {
|
|
37
|
+
console.error("Failed to start generated server:", error);
|
|
38
|
+
}
|
|
39
|
+
`;
|
|
40
|
+
const result = spawnSync(process.execPath, ["--input-type=module", "--eval", source], {
|
|
41
|
+
encoding: "utf8"
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
assert.equal(result.status, 0, String(result.stderr || ""));
|
|
45
|
+
assert.match(result.stderr, /Failed to start generated server:/u);
|
|
46
|
+
assert.match(result.stderr, /Provider "json-rest-api\.core" failed during boot\(\)\./u);
|
|
47
|
+
assert.match(result.stderr, /DB_CLIENT is required\. Use mysql2 or pg\./u);
|
|
48
|
+
});
|