Skip to content

Commit 889c553

Browse files
authored
fix: catch FiddleRunner spawn error (#1197)
1 parent b69d17e commit 889c553

File tree

1 file changed

+29
-16
lines changed

1 file changed

+29
-16
lines changed

src/renderer/runner.ts

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -387,31 +387,44 @@ export class Runner {
387387
// Add user-specified cli flags if any have been set.
388388
const options = [dir, '--inspect'].concat(executionFlags);
389389

390+
const cleanup = async () => {
391+
flushOutput();
392+
393+
this.appState.isRunning = false;
394+
this.child = null;
395+
396+
// Clean older folders
397+
await window.ElectronFiddle.app.fileManager.cleanup(dir);
398+
await this.deleteUserData();
399+
};
400+
390401
return new Promise(async (resolve, _reject) => {
391-
this.child = await fiddleRunner.spawn(
392-
isValidBuild && localPath ? Installer.getExecPath(localPath) : version,
393-
dir,
394-
{ args: options, cwd: dir, env },
395-
);
402+
try {
403+
this.child = await fiddleRunner.spawn(
404+
isValidBuild && localPath
405+
? Installer.getExecPath(localPath)
406+
: version,
407+
dir,
408+
{ args: options, cwd: dir, env },
409+
);
410+
} catch (e) {
411+
pushOutput(`Failed to spawn Fiddle: ${e.message}`);
412+
await cleanup();
413+
return resolve(RunResult.FAILURE);
414+
}
415+
396416
this.appState.isRunning = true;
397417

398418
pushOutput(`Electron v${version} started.`);
399419

400-
this.child.stdout!.on('data', (data) =>
420+
this.child?.stdout?.on('data', (data) =>
401421
pushOutput(data, { bypassBuffer: false }),
402422
);
403-
this.child.stderr!.on('data', (data) =>
423+
this.child?.stderr?.on('data', (data) =>
404424
pushOutput(data, { bypassBuffer: false }),
405425
);
406-
this.child.on('close', async (code, signal) => {
407-
flushOutput();
408-
409-
this.appState.isRunning = false;
410-
this.child = null;
411-
412-
// Clean older folders
413-
await window.ElectronFiddle.app.fileManager.cleanup(dir);
414-
await this.deleteUserData();
426+
this.child?.on('close', async (code, signal) => {
427+
await cleanup();
415428

416429
if (typeof code !== 'number') {
417430
pushOutput(`Electron exited with signal ${signal}.`);

0 commit comments

Comments
 (0)