Add extended diagnostics logging
- Electron crash handlers (render-process-gone, child-process-gone, unresponsive/responsive, process warnings) with a circuit-breaker auto-reload for renderer crashes - Renderer error capture (window.onerror, unhandledrejection, React ErrorBoundary) forwarded to the main log via a one-way IPC channel - Memory-pressure heartbeat measured against the V8 heap_size_limit - Gated DEBUG log level (RD_DEBUG) and an in-memory ring of recent WARN/ERROR lines, exposed via the /errors endpoint and support bundle - Disk-error classification (ENOSPC etc.) on download failures and integrity-check pass/fail logging
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { createErrorRing } from "../src/main/error-ring";
|
||||
|
||||
describe("createErrorRing", () => {
|
||||
it("keeps entries in insertion order", () => {
|
||||
const ring = createErrorRing(10);
|
||||
ring.push({ ts: "t1", level: "ERROR", message: "a" });
|
||||
ring.push({ ts: "t2", level: "WARN", message: "b" });
|
||||
expect(ring.snapshot().map((e) => e.message)).toEqual(["a", "b"]);
|
||||
expect(ring.size()).toBe(2);
|
||||
});
|
||||
|
||||
it("caps at capacity by dropping the oldest", () => {
|
||||
const ring = createErrorRing(3);
|
||||
for (const m of ["a", "b", "c", "d", "e"]) {
|
||||
ring.push({ ts: m, level: "ERROR", message: m });
|
||||
}
|
||||
expect(ring.snapshot().map((e) => e.message)).toEqual(["c", "d", "e"]);
|
||||
expect(ring.size()).toBe(3);
|
||||
});
|
||||
|
||||
it("snapshot returns a copy, not the live buffer", () => {
|
||||
const ring = createErrorRing(5);
|
||||
ring.push({ ts: "t", level: "WARN", message: "x" });
|
||||
const snap = ring.snapshot();
|
||||
snap.push({ ts: "t2", level: "ERROR", message: "injected" });
|
||||
expect(ring.snapshot().map((e) => e.message)).toEqual(["x"]);
|
||||
});
|
||||
|
||||
it("clear empties the ring", () => {
|
||||
const ring = createErrorRing(5);
|
||||
ring.push({ ts: "t", level: "ERROR", message: "x" });
|
||||
ring.clear();
|
||||
expect(ring.snapshot()).toEqual([]);
|
||||
expect(ring.size()).toBe(0);
|
||||
});
|
||||
|
||||
it("coerces a non-positive capacity to at least 1", () => {
|
||||
const ring = createErrorRing(0);
|
||||
ring.push({ ts: "t1", level: "ERROR", message: "a" });
|
||||
ring.push({ ts: "t2", level: "ERROR", message: "b" });
|
||||
expect(ring.snapshot().map((e) => e.message)).toEqual(["b"]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,49 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { classifyDiskError } from "../src/main/fs-error";
|
||||
import { isDebugFlagEnabled } from "../src/main/logger";
|
||||
|
||||
describe("classifyDiskError", () => {
|
||||
it("maps ENOSPC from an error code to a disk-full reason", () => {
|
||||
const err = Object.assign(new Error("write ENOSPC"), { code: "ENOSPC" });
|
||||
expect(classifyDiskError(err)).toMatch(/Festplatte voll/);
|
||||
});
|
||||
|
||||
it("maps EACCES from a code to a permission reason", () => {
|
||||
const err = Object.assign(new Error("nope"), { code: "EACCES" });
|
||||
expect(classifyDiskError(err)).toMatch(/Zugriff verweigert/);
|
||||
});
|
||||
|
||||
it("lower-case codes are normalized", () => {
|
||||
const err = Object.assign(new Error("x"), { code: "enospc" });
|
||||
expect(classifyDiskError(err)).toMatch(/ENOSPC/);
|
||||
});
|
||||
|
||||
it("falls back to scanning the message text when no code is present", () => {
|
||||
expect(classifyDiskError(new Error("operation failed: ENOSPC on volume"))).toMatch(/Festplatte voll/);
|
||||
});
|
||||
|
||||
it("handles a plain string error", () => {
|
||||
expect(classifyDiskError("EROFS: read-only file system")).toMatch(/schreibgeschützt/);
|
||||
});
|
||||
|
||||
it("returns null for an unrelated error", () => {
|
||||
expect(classifyDiskError(new Error("write_drain_timeout"))).toBeNull();
|
||||
expect(classifyDiskError(new Error("premature close"))).toBeNull();
|
||||
expect(classifyDiskError(null)).toBeNull();
|
||||
expect(classifyDiskError(undefined)).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("isDebugFlagEnabled", () => {
|
||||
it("is true for affirmative values", () => {
|
||||
for (const v of ["1", "true", "TRUE", "yes", "on", " on "]) {
|
||||
expect(isDebugFlagEnabled(v)).toBe(true);
|
||||
}
|
||||
});
|
||||
|
||||
it("is false for empty/negative/garbage values", () => {
|
||||
for (const v of [undefined, "", "0", "false", "off", "no", "maybe"]) {
|
||||
expect(isDebugFlagEnabled(v)).toBe(false);
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user