From d4d7790d17399b422ed640e3f3e5159a256d8b8b Mon Sep 17 00:00:00 2001 From: igorgudelj Date: Mon, 2 Mar 2026 23:46:32 +0100 Subject: [PATCH 1/2] Fix uncaught exception in stopProcess when process already exited Wrap killSync + proc.kill() in try-catch. killSync throws when the OS process has already terminated, causing an error dialog on Windows. Fixes NativePHP/desktop#89 --- .../electron-plugin/src/server/api/childProcess.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/resources/electron/electron-plugin/src/server/api/childProcess.ts b/resources/electron/electron-plugin/src/server/api/childProcess.ts index bcf0b5d..01b07a2 100644 --- a/resources/electron/electron-plugin/src/server/api/childProcess.ts +++ b/resources/electron/electron-plugin/src/server/api/childProcess.ts @@ -195,9 +195,13 @@ function stopProcess(alias) { console.log('Process [' + alias + '] stopping with PID [' + proc.pid + '].'); - // @ts-ignore - killSync(proc.pid, 'SIGTERM', true); // Kill tree - proc.kill(); // Does not work but just in case. (do not put before killSync) + try { + // @ts-ignore + killSync(proc.pid, 'SIGTERM', true); // Kill tree + proc.kill(); // Does not work but just in case. (do not put before killSync) + } catch (e) { + // Process already exited — nothing to kill + } } export function stopAllProcesses() { From 1312b7b0703e20e4021b62e6f5fff27bddca09b4 Mon Sep 17 00:00:00 2001 From: Igor Gudelj Date: Wed, 4 Mar 2026 11:29:53 +0100 Subject: [PATCH 2/2] Add console.log in catch block when process already exited --- .../electron/electron-plugin/src/server/api/childProcess.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/electron/electron-plugin/src/server/api/childProcess.ts b/resources/electron/electron-plugin/src/server/api/childProcess.ts index 01b07a2..2e6c54f 100644 --- a/resources/electron/electron-plugin/src/server/api/childProcess.ts +++ b/resources/electron/electron-plugin/src/server/api/childProcess.ts @@ -200,7 +200,7 @@ function stopProcess(alias) { killSync(proc.pid, 'SIGTERM', true); // Kill tree proc.kill(); // Does not work but just in case. (do not put before killSync) } catch (e) { - // Process already exited — nothing to kill + console.log('Process [' + alias + '] already exited — nothing to kill.'); } }