fix(electron): report a failed ffmpeg download as ELECTRON_INSTALL_FAILED and read a package.json with a byte order mark

KD
22m ago
+65-10

What

  • A failed ffmpeg download for video fails the recording with ELECTRON_INSTALL_FAILED, an infrastructure error, as a failed Electron download does. It used to surface as ENGINE_FAILURE.
  • A machine with no VP9 ffmpeg on its PATH is checked for one once per process, not before every recording.
  • An app whose package.json starts with a byte order mark (which some Windows editors write) passes the app.appPath check. Electron reads past the mark, but the check said the file was not valid JSON.

Why

Three small Electron engine bugs found while working on the Electron download. A machine that cannot reach GitHub saw ENGINE_FAILURE for a network failure, which reads as an engine bug and is not counted as infrastructure. A CI machine with no ffmpeg ran ffmpeg -encoders before each recording. A Windows project with a BOM in package.json failed before the first test with a wrong message.

The lock around the Electron download that this PR started with is left to #2470, which holds the lock in the process that runs install.js and also handles a stale path.txt. This branch merges with #2470 without conflicts.

How it works

  1. translate returns an InfrastructureError unchanged (packages/electron/src/errors.ts:43), as it already did for ConfigurationError and TestError. Before, it fell through to the generic wrap, since an InfrastructureError is not an EngineError. The only one raised inside an operation's budget is ensureFfmpeg in video start, which sends no input.
  2. ensureFfmpeg keeps a miss on the PATH (null) as well as a hit (packages/electron/src/ffmpeg.ts:60); ??= re-ran the probe after every null.
  3. appPathProblem strips a leading  before it parses package.json (packages/electron/src/executable.ts:256).
  4. Docs: reference/errors.mdx lists the ffmpeg download under ELECTRON_INSTALL_FAILED. The reference's Video row says a failed download fails the recording and gives the order the engine finds ffmpeg in, with the cached download before the PATH. The guide no longer repeats that order.

Verified

Ran it locally: yes, on macOS (Apple Silicon).

  • The Electron package's unit tests pass (115), with typecheck and oxlint. git merge-tree against #2470's head (fa55008c0) reports no conflicts.
  • main against this branch: this branch's tests run against origin/main's packages/electron/src. These fail there and pass here:
SuiteTestmainthis PR
unittranslate leaves a refusal by policy or of the test's own input as it isfailspasses
unitensureFfmpeg checks the PATH for ffmpeg once, and fails a download that failed with ELECTRON_INSTALL_FAILEDfailspasses
unitapp.appPath takes a main script, or a directory whose main script exists, and says what is wrong otherwisefailspasses
  • Benchmark: not run, the remaining changes touch only install and ffmpeg error paths the testbed suite never takes.
  • Video: none. Nothing changes on screen.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Documentation
    • Clarified how video recording locates or downloads ffmpeg, including configuration options and the errors shown when it is unavailable.
  • Bug Fixes
    • Failed ffmpeg downloads now report the appropriate installation error.
    • Fixed app detection when a package file begins with a byte-order mark.
    • Avoided repeating the ffmpeg availability check after it has already found ffmpeg unavailable.