fix(agent-core): guard harness error normalization

This commit is contained in:
Vincent Koc
2026-06-05 10:12:53 +02:00
parent 68a26ba177
commit 79dd9cfc18
2 changed files with 21 additions and 1 deletions

View File

@@ -0,0 +1,20 @@
import { describe, expect, it } from "vitest";
import { toError } from "./types.js";
describe("toError", () => {
it("normalizes hostile non-Error values without stringifying them", () => {
const hostile = {
toJSON() {
throw new Error("json denied");
},
toString() {
throw new Error("stringification denied");
},
};
const error = toError(hostile);
expect(error).toBeInstanceOf(Error);
expect(error.message).toBe("Unknown thrown value");
});
});

View File

@@ -50,7 +50,7 @@ export function toError(error: unknown): Error {
try {
return new Error(JSON.stringify(error));
} catch {
return new Error(String(error));
return new Error("Unknown thrown value");
}
}