electron / electron/forge

Error: spawn C:\Users<...>\Update.exe ENOENT

Open
#3,242 1 comment 0 reactions 0 assignees View on GitHub
bug maker/squirrel platform/windows
Dominant language
TypeScript
Stars
7.1k
Forks
641
Avg merge
3d 1h
Merged PRs (30d)
30

Description

### Pre-flight checklist

- [X] I have read the [contribution documentation](https://github.com/electron/forge/blob/main/CONTRIBUTING.md) for this project.
- [X] I agree to follow the [code of conduct](https://github.com/electron/electron/blob/main/CODE_OF_CONDUCT.md) that this project uses.
- [X] I have searched the issue tracker for a bug that matches the one I want to file, without success.

### Electron Forge version

6.1.1

### Electron version

22.3.8

### Operating system

Windows 10

### Last known working Electron Forge version

none

### Expected behavior

Should not crash

### Actual behavior

My electron application is gaining popularity and reached several thousand installations per month. I had to create my own crash reproting mechanism capable of reporting JS exceptions (since things like backtrace only report on native crashes). So if there is js exception during execution I get anonmous report about it.

Once in a while (I would estimate in 1-2% of cases) when person first installs an application, there is an exception:
```
Error: spawn C:\Users\PC\AppData\Local\tonfotos\Update.exe ENOENT
at ChildProcess._handle.onexit (node:internal/child_process:283:19)
at onErrorNT (node:internal/child_process:478:16)
at process.processTicksAndRejections (node:internal/process/task_queues:83:21) {
errno: -4058,
code: 'ENOENT',
syscall: 'spawn C:\\Users\\PC\\AppData\\Local\\tonfotos\\Update.exe',
path: 'C:\\Users\\PC\\AppData\\Local\\tonfotos\\Update.exe',
spawnargs: [ '--createShortcut=tonfotos.exe' ]
} uncaughtException
```

However, as I understand, when person runs installation second time, it goes without error.

### Steps to reproduce

I do not know the way to reproduce. This is rare bug that only happens in production at customer side during first installation of applicaiton. How I know this only happens during installation? This is because my crash report contains command line parameters, and during this crash it has `--squirrel-install`

### Additional information

I made some digging and I believe it is this piece of code (inside electron-squirrel-startup) that throws:
https://github.com/mongodb-js/electron-squirrel-startup/blob/29221a02c38bc43655e5c67e189e2a25105753f6/index.js#L9

According to documentation, we are supposed to run this code like this:
https://www.electronforge.io/config/makers/squirrel.windows#handling-startup-events

And I believe, we all do as this is just part of the boilerplate. But problem is, this code does not have any error protection, and will throw if there is no Update.exe file in place, which it does, as we can clearly see. I tried to wrap this piece of code into try...catch like that, but for some reason it does not help (I don't know why honestly):
```
let this_is_technical_run;
try {
this_is_technical_run = require('electron-squirrel-startup'); // eslint-disable-line global-require
}
catch (err) {
_e('Error in require("electron-squirrel-startup")', err);
}

if (this_is_technical_run) {
...
}
else {
...
}
```

So, I see two issues here:

MAJOR - For some unknown reason, this code gets run BEFORE file copying is finished, which leads to malfunction with some non zero probablility. Actually, I also get other crashes from time to time, not just regarding Update.exe, but regarding some native libraries used in my app, they are also may be missing for some misterious reason. But if you run installation again - everything works just fine.

MINOR (but still annoying) - there is no checks for error. Since this one in particular will only fail to create shortcut, I don't think this is good enough reason to crash whole app with unhandled expection. I would be just enough to writhe error to console and move on.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.