Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

fix(diagnostics): write undefined, functions and symbols to main.log as text

Marc Diazb9d4fa687e37
diff --git a/electron/diagnostics/main-log-file.test.ts b/electron/diagnostics/main-log-file.test.ts
index 1ffe326c7..d6f1e8425 100644
--- a/electron/diagnostics/main-log-file.test.ts
+++ b/electron/diagnostics/main-log-file.test.ts
@@ -85,6 +85,15 @@ describe("MainLogFile", () => {
expect(text).toContain('info {"a":1}');
});
+ it("writes values with no JSON form as text", () => {
+ silenceConsole();
+ make().install(dir, "launch");
+ console.log("value:", undefined);
+
+ const text = fs.readFileSync(path.join(dir, "main.log"), "utf-8");
+ expect(text).toContain("log value: undefined");
+ });
+
it("moves a full file to main.old.log and never keeps more than two files", () => {
silenceConsole();
make(200).install(dir, "launch");
diff --git a/electron/diagnostics/main-log-file.ts b/electron/diagnostics/main-log-file.ts
index d366ba27c..da0486d4f 100644
--- a/electron/diagnostics/main-log-file.ts
+++ b/electron/diagnostics/main-log-file.ts
@@ -266,7 +266,8 @@ function formatArgs(args: unknown[]): string {
// An Error's message and stack are not enumerable, so JSON.stringify writes `{}`.
if (arg instanceof Error) return arg.stack ?? `${arg.name}: ${arg.message}`;
try {
- return JSON.stringify(arg);
+ // `undefined`, functions and symbols have no JSON form: write them as the console does.
+ return JSON.stringify(arg) ?? String(arg);
} catch {
return String(arg);
}