mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-06 05:51:15 +08:00
fix(agent-core): guard harness error normalization
This commit is contained in:
20
packages/agent-core/src/harness/types.test.ts
Normal file
20
packages/agent-core/src/harness/types.test.ts
Normal 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");
|
||||
});
|
||||
});
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user