Skip to content

Commit 828d257

Browse files
committed
Add error reporting for SITL child process failures
Previously, SITL spawn errors and unexpected exits were completely silent - the renderer never subscribed to child process error/exit events. Now errors are logged to both console and the GUI log so users can see why Demo mode or SITL connections fail. Also removes the ineffective useShell option (not a valid Node.js spawn property, was silently ignored).
1 parent 12e6832 commit 828d257

3 files changed

Lines changed: 32 additions & 14 deletions

File tree

js/main/child_process.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,20 @@ import { spawn } from 'node:child_process'
33
const child_process = {
44
_processes: [],
55

6-
start: function (command, args, opts, window) {
6+
start: function (command, args, opts, window) {
77
var process;
88
try {
99
process = spawn(command, args, opts);
1010
} catch (err) {
11-
console.log(err);
11+
console.log(`[child_process] Spawn error: ${err.message}`);
12+
if (!window.isDestroyed()) {
13+
window.webContents.send('onChildProcessError', { message: `Spawn error: ${err.message}` });
14+
}
1215
return -1;
1316
}
14-
17+
1518
this._processes.push(process);
16-
19+
1720
process.stdout.on('data', (data) => {
1821
if (!window.isDestroyed()) {
1922
window.webContents.send('onChildProcessStdout', data.toString());
@@ -27,8 +30,15 @@ const child_process = {
2730
});
2831

2932
process.on('error', (error) => {
33+
console.log(`[child_process] Error: ${error.message}`);
34+
if (!window.isDestroyed()) {
35+
window.webContents.send('onChildProcessError', { message: error.message });
36+
}
37+
});
38+
39+
process.on('exit', (code, signal) => {
3040
if (!window.isDestroyed()) {
31-
window.webContents.send('onChildProcessError', error);
41+
window.webContents.send('onChildProcessExit', { code, signal });
3242
}
3343
});
3444
},

js/main/preload.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,10 @@ contextBridge.exposeInMainWorld('electronAPI', {
9595
return handler;
9696
},
9797
offChildProcessError: (handler) => ipcRenderer.removeListener('onChildProcessError', handler),
98+
onChildProcessExit: (callback) => {
99+
const handler = (_event, data) => callback(data);
100+
ipcRenderer.on('onChildProcessExit', handler);
101+
return handler;
102+
},
103+
offChildProcessExit: (handler) => ipcRenderer.removeListener('onChildProcessExit', handler),
98104
});

js/sitl.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -183,17 +183,19 @@ var SITLProcess = {
183183

184184
spawn: function(path, args) {
185185

186-
var opts = undefined;
187-
if (GUI.operating_system == 'Linux')
188-
opts = { useShell: true };
189-
190-
window.electronAPI.startChildProcess(path, args, opts);
191-
192-
if (this.processHandle == -1) {
186+
window.electronAPI.onChildProcessError((error) => {
187+
console.log(`SITL error: ${error.message || JSON.stringify(error)}`);
188+
GUI.log(`SITL error: ${error.message || JSON.stringify(error)}`);
189+
});
190+
window.electronAPI.onChildProcessExit((data) => {
191+
if (data.code !== 0 && data.code !== null) {
192+
console.log(`SITL process exited with code ${data.code}`);
193+
GUI.log(`SITL process exited with code ${data.code}`);
194+
}
193195
this.isRunning = false;
194-
return;
195-
}
196+
});
196197

198+
window.electronAPI.startChildProcess(path, args);
197199
this.isRunning = true;
198200
},
199201

0 commit comments

Comments
 (0)