fix(errors): warn on raw stringify fallback

This commit is contained in:
ZacharyZhang-NY committed 2026-04-22 19:04:53 -04:00
1 parent ee1ea4fd8c
commit 1883d9d9d3
2 files changed
+57 -1

No files matched your search

+42
View File
@@ -0,0 +1,42 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
vi.mock("electron-log/main.js", () => ({
default: {
warn: vi.fn(),
},
}));
import log from "electron-log/main.js";
import { classifyUnknownError } from "../../src/main/errors/taxonomy";
const warn = vi.mocked(log.warn);
describe("error taxonomy", () => {
beforeEach(() => {
warn.mockClear();
});
it("warns once when raw thrown values cannot be JSON stringified", () => {
const raw: { self?: unknown } = {};
raw.self = raw;
const first = classifyUnknownError(raw, {
kind: "recoverable",
code: "test.raw.cyclic",
message: "Cyclic raw value.",
});
const second = classifyUnknownError(raw, {
kind: "recoverable",
code: "test.raw.cyclic",
message: "Cyclic raw value.",
});
expect(first.context?.raw).toBe("[object Object]");
expect(second.context?.raw).toBe("[object Object]");
expect(warn).toHaveBeenCalledTimes(1);
expect(warn).toHaveBeenCalledWith(
"[errors] stringifyRaw failed; using String(value) for raw thrown value.",
expect.stringContaining("circular"),
);
});
});