Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.
TypeScript cross-platformelectronffmpegopen-sourceproduct-demorustscreen-capturescreen-recorderscreen-recordingscreen-studioscreencastspeech-to-texttypescriptvideo-editingvideo-editorwaylandwgpuwhisper
fix(stt): keep one voice on a spawn error too, not just on an exit
EtienneLescotbf961eefd19a
diff --git a/electron/stt/whisperServer.test.ts b/electron/stt/whisperServer.test.tsindex bc7800b16..b29ba2a29 100644--- a/electron/stt/whisperServer.test.ts+++ b/electron/stt/whisperServer.test.ts@@ -551,6 +551,54 @@ describe("WhisperServerManager", () => {}});+ it("logs a spawn error once, the same as a death by exit", async () => {+ // ponytail: the `error` listener is the OTHER way a helper never reaches+ // readiness, and it reaches the startup catch by the same route — the+ // `exitedBeforeReady` race rejects on `error` as well as on `exit`. Whatever+ // keeps one voice on an exit has to keep one voice here too, or the fix has+ // simply moved the duplicate into the branch nobody looked at.+ const fs = await import("node:fs/promises");+ const { spawn } = await import("node:child_process");+ const dir = await mkdtemp(path.join(tmpdir(), "whisper-spawn-error-"));+ const errors = vi.spyOn(console, "error").mockImplementation(() => undefined);+ try {+ const modelPath = path.join(dir, "ggml-small-q8_0.bin");+ const fakeBinaryPath = path.join(+ dir,+ process.platform === "win32" ? "whisper-stt-server.exe" : "whisper-stt-server",+ );+ await fs.writeFile(modelPath, "dummy-ggml");+ await fs.writeFile(fakeBinaryPath, "x", { mode: 0o755 });++ const child = Object.assign(new EventEmitter(), {+ stdout: new EventEmitter(),+ stderr: new EventEmitter(),+ pid: undefined,+ kill: vi.fn(() => true),+ });+ vi.mocked(spawn).mockImplementationOnce(() => {+ // No "exit" at all: the process never came up, so only "error" fires.+ queueMicrotask(() => child.emit("error", new Error("spawn EACCES")));+ return child as never;+ });++ const mgr = new WhisperServerManager();+ await expect(+ mgr.start({ modelPath, binaryPath: fakeBinaryPath, backend: "whispercpp-cpu" }),+ ).rejects.toThrow(/spawn EACCES/);++ const stt = errors.mock.calls.map(String).filter((line) => line.startsWith("[stt] "));+ expect(stt, `lignes [stt] émises : ${JSON.stringify(stt)}`).toHaveLength(1);+ expect(stt[0]).toMatch(/spawn error: spawn EACCES/);+ // The listener cleared the startup state, so nothing is left claiming a+ // helper is up — `status` must agree with the log.+ expect(mgr.status.running).toBe(false);+ } finally {+ errors.mockRestore();+ await rm(dir, { recursive: true, force: true });+ }+ });+it("logs a readiness timeout, which no exit listener would ever see", async () => {// The other direction: nothing exits, so the startup catch is the ONLY voice// on this failure and must not be silenced by the de-duplication above.diff --git a/electron/stt/whisperServer.ts b/electron/stt/whisperServer.tsindex 132e60b91..950dc879c 100644--- a/electron/stt/whisperServer.ts+++ b/electron/stt/whisperServer.ts@@ -304,7 +304,19 @@ export class WhisperServerManager {}});child.once("error", (err) => {- this.recordError(`spawn error: ${err.message}`);+ // ponytail: the same shape as the `exit` listener above, and for the same+ // reason. A spawn error reaches the startup catch by the same route — the+ // `exitedBeforeReady` race rejects on `error` too — so without clearing+ // the startup state here, that catch cannot tell this failure has already+ // been reported and logs it a second time in different words. Clearing is+ // also just true: a child that never spawned is not a helper that is up,+ // and `status` said it was.+ if (this.process === child) {+ this.recordError(`spawn error: ${err.message}`);+ this.process = null;+ this.port = null;+ this.startedAtMs = null;+ }});const exitedBeforeReady = new Promise<never>((_, reject) => {