diff --git a/packages/cli/src/browser/preflight.test.ts b/packages/cli/src/browser/preflight.test.ts index 53001c0eb5..7ecbe6e7a5 100644 --- a/packages/cli/src/browser/preflight.test.ts +++ b/packages/cli/src/browser/preflight.test.ts @@ -170,6 +170,24 @@ describe("runEnvironmentChecks", () => { expect(result.ffmpegPath).toBeUndefined(); }); + it.each([ + { error: { code: "ENOENT" }, said: "(ENOENT)" }, + { error: { code: "EACCES" }, said: "(EACCES)" }, + { error: { signal: "SIGKILL" }, said: "(signal SIGKILL)" }, + { error: { code: "ETIMEDOUT", signal: "SIGTERM" }, said: "(ETIMEDOUT)" }, + ])("names how FFmpeg failed to start: $said", async ({ error, said }) => { + runProcess.mockImplementation((binaryPath: string) => { + if (binaryPath !== process.env.HYPERFRAMES_FFMPEG_PATH) + return Promise.resolve({ stdout: "ffprobe version 7.1.1\n", stderr: "" }); + throw Object.assign(new Error("spawn failed"), error); + }); + + const result = await runEnvironmentChecks(); + const ffmpeg = result.outcomes.find((outcome) => outcome.name === "FFmpeg"); + + expect(ffmpeg?.detail).toBe(`Failed to run "${process.execPath}" -version ${said}.`); + }); + // Windows DLL advice only on Windows; elsewhere the platform install hint. describe("FFmpeg cannot-start hint is platform-specific", () => { const realPlatform = process.platform; diff --git a/packages/cli/src/browser/preflight.ts b/packages/cli/src/browser/preflight.ts index a01c76862d..588c069fe5 100644 --- a/packages/cli/src/browser/preflight.ts +++ b/packages/cli/src/browser/preflight.ts @@ -95,9 +95,21 @@ async function readToolVersion( }; } catch (error) { if (signal?.aborted) signal.throwIfAborted(); - const status = - typeof error === "object" && error !== null && "status" in error ? error.status : undefined; - const exitDetail = typeof status === "number" ? ` (exit code ${status})` : ""; + const field = (name: string) => + typeof error === "object" && error !== null && name in error + ? (error as Record)[name] + : undefined; + const status = field("status"); + const code = field("code"); + const killedBy = field("signal"); + const exitDetail = + typeof status === "number" + ? ` (exit code ${status})` + : typeof code === "string" + ? ` (${code})` + : typeof killedBy === "string" + ? ` (signal ${killedBy})` + : ""; return { ok: false, detail: `Failed to run "${binaryPath}" -version${exitDetail}.`,