fix(electron): name the exe to start for a wrong Windows executablePath

Merged
OK
1d ago
+145-19

What

On Windows, electron({ executablePath }) is checked to be a program before the run starts, and the error names the file to use instead:

executablePath namesError ends with
a shortcut (.lnk)it is a shortcut: name the .exe it points to
the app's foldername the app's .exe inside the folder (it holds MyApp.exe, Uninstall MyApp.exe)
a path without .exename the file with its extension, C:\...\MyApp.exe
a Squirrel launcher (MyApp.exe beside Update.exe)name the app itself, C:\...\app-3.7.1\MyApp.exe

e2e doctor reports the same. The docs page gets a Windows example for a packaged app.

Why

Found while driving installed apps on a Windows Server 2025 machine. Windows has no execute bit, so the check accepted any readable file:

  • A desktop shortcut passed the check and e2e doctor, then failed every test with could not launch ...lnk: spawn EFTYPE.
  • A folder or a path without .exe said not an executable file with no fix. macOS already gets one for a .app bundle.
  • GitHub Desktop, installed by Squirrel, has a GitHubDesktop.exe at the install root that starts app-3.7.1\GitHubDesktop.exe and exits. Every test failed with the app quit before it opened a window (with exit code 0).

How it works

  1. isExecutableFile takes the platform. On Windows it reads the file's first two bytes and accepts a program image (MZ), which is what CreateProcess starts. Other platforms keep the execute-permission check. packages/electron/src/executable.ts:56
  2. squirrelApp recognizes a Squirrel launcher by its layout: Update.exe beside it, and app-<version> folders that hold an exe of its name. With one version installed it returns that exe's path. With several it names the folders, since which one the launcher starts is Squirrel's rule and guessing it could name a stale build. executable.ts:96
  3. executableHint builds the hint for a path that is no executable: the .app bundle text as before, then on Windows the shortcut, the missing extension, and the folder. The last two go through squirrelApp, so they never point at a launcher. executable.ts:113
  4. locateExecutable refuses a launcher that passed the image check. executable.ts:142
  5. resolveExecutable and describeExecutable take an optional platform so the unit tests cover the Windows rules on any OS.

Not changed: an app execution alias (%LOCALAPPDATA%\Microsoft\WindowsApps\*.exe, Store installs) is refused on main too, because stat fails on it with EACCES.

Issue

None filed. Found in a Windows verification pass of @e2e-dev/electron.

Verified

Ran it locally: yes, on a Windows Server 2025 machine (interactive desktop session), with the testbed app packaged by electron-builder (NSIS) and installed, and GitHub Desktop 3.7.1 installed by its Squirrel installer.

e2e run with each executablePath:

executablePathmainthis PR
...\Desktop\E2E Testbed App.lnk12 tests fail: could not launch ...lnk: spawn EFTYPE; doctor passesconfig error: it is a shortcut: name the .exe it points to (its Target, under Properties)
...\Programs\e2e-testbed-packagedwhich is not an executable file...; name the app's .exe inside the folder (it holds E2E Testbed App.exe, Uninstall E2E Testbed App.exe)
...\e2e-testbed-packaged\E2E Testbed Appwhich is not an executable file...; name the file with its extension, C:\...\E2E Testbed App.exe
...\GitHubDesktop\GitHubDesktop.exetest fails: the app quit before it opened a window (with exit code 0)config error: the launcher its installer left there: it starts the app and exits, so name the app itself, C:\...\GitHubDesktop\app-3.7.1\GitHubDesktop.exe
...\GitHubDesktopwhich is not an executable file...; name the app's .exe, C:\...\GitHubDesktop\app-3.7.1\GitHubDesktop.exe
...\e2e-testbed-packaged\E2E Testbed App.exe12 passed12 passed
===== C:\Users\Administrator\Desktop\E2E Testbed App.lnk
electron({ executablePath }) names C:\Users\Administrator\Desktop\E2E Testbed App.lnk, which is not an executable file; it is a shortcut: name the .exe it points to (its Target, under Properties)
===== C:\Users\Administrator\AppData\Local\GitHubDesktop\GitHubDesktop.exe
electron({ executablePath }) names C:\Users\Administrator\AppData\Local\GitHubDesktop\GitHubDesktop.exe, the launcher its installer left there: it starts the app and exits, so name the app itself, C:\Users\Administrator\AppData\Local\GitHubDesktop\app-3.7.1\GitHubDesktop.exe
===== good
      Tests  12 passed (12)

Unit tests on Windows and macOS: pnpm --filter @e2e-dev/electron test, 99 passed on both. pnpm check passes.

No terminal recording: the change is one error line, quoted above. No docs screenshot: the page gains one code block and one paragraph.