Skip to content

Commit 69817a1

Browse files
committed
fix(desktop): flush --version before hard exit
console.log then process.exit can drop piped stdout on Electron before whenReady. writeStdoutLineSync writes fd 1, swallows EPIPE, then main still process.exit(0). Implemented with grok-4.6 in T3 Code.
1 parent b6a1984 commit 69817a1

3 files changed

Lines changed: 36 additions & 2 deletions

File tree

‎apps/desktop/src/app/DesktopPreReadyPlatform.test.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,27 @@ describe("DesktopPreReadyPlatform", () => {
8888
assert.isFalse(DesktopPreReadyPlatform.isVersionRequest([]));
8989
});
9090

91+
it("writes a version line to stdout synchronously and swallows EPIPE", () => {
92+
const writes: Array<{ fd: number; data: string }> = [];
93+
DesktopPreReadyPlatform.writeStdoutLineSync("1.2.3", (fd, data) => {
94+
writes.push({ fd, data });
95+
});
96+
assert.deepEqual(writes, [{ fd: 1, data: "1.2.3\n" }]);
97+
98+
DesktopPreReadyPlatform.writeStdoutLineSync("1.2.3", () => {
99+
throw Object.assign(new Error("broken pipe"), { code: "EPIPE" });
100+
});
101+
102+
try {
103+
DesktopPreReadyPlatform.writeStdoutLineSync("1.2.3", () => {
104+
throw Object.assign(new Error("bad fd"), { code: "EBADF" });
105+
});
106+
assert.fail("expected EBADF to propagate");
107+
} catch (error) {
108+
assert.equal((error as NodeJS.ErrnoException).code, "EBADF");
109+
}
110+
});
111+
91112
it.effect(
92113
"acquires a synchronous pre-ready layer before an asynchronous Clerk-shaped layer",
93114
() =>

‎apps/desktop/src/app/DesktopPreReadyPlatform.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,20 @@ export function isVersionRequest(argv: ReadonlyArray<string>): boolean {
3333
return argv.includes("--version") || argv.includes("-V");
3434
}
3535

36+
export function writeStdoutLineSync(
37+
line: string,
38+
writeSync: (fd: number, data: string) => void = (fd, data) => {
39+
NodeFS.writeSync(fd, data);
40+
},
41+
): void {
42+
try {
43+
writeSync(1, `${line}\n`);
44+
} catch (error) {
45+
const err = error as NodeJS.ErrnoException;
46+
if (err.code !== "EPIPE") throw error;
47+
}
48+
}
49+
3650
export const resolveEarlyLinuxElectronOptionsFromProcess =
3751
(): DesktopEarlyElectronStartup.EarlyLinuxElectronOptions =>
3852
DesktopEarlyElectronStartup.resolveEarlyLinuxElectronOptions({

‎apps/desktop/src/main.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,7 @@ const desktopRuntimeLayer = desktopClerkLayer.pipe(
217217
);
218218

219219
if (DesktopPreReadyPlatform.isVersionRequest(process.argv)) {
220-
// @effect-diagnostics-next-line globalConsole:off - print and exit before the Effect runtime exists.
221-
console.log(Electron.app.getVersion());
220+
DesktopPreReadyPlatform.writeStdoutLineSync(Electron.app.getVersion());
222221
process.exit(0);
223222
}
224223

0 commit comments

Comments
 (0)