fix(core): handle GUI editor non-zero exit codes gracefully (#20376)

Co-authored-by: Jacob Richman <jacob314@gmail.com>
This commit is contained in:
sinisterchill
2026-03-10 05:21:10 +05:30
committed by GitHub
parent 43eb74ac59
commit 1e1e7e349d
2 changed files with 88 additions and 6 deletions

View File

@@ -323,15 +323,30 @@ export async function openDiff(
shell: process.platform === 'win32',
});
// Guard against both 'error' and 'close' firing for a single failure,
// which would emit ExternalEditorClosed twice and attempt to settle
// the promise twice.
let isSettled = false;
childProcess.on('close', (code) => {
if (code === 0) {
resolve();
} else {
reject(new Error(`${editor} exited with code ${code}`));
if (isSettled) return;
isSettled = true;
if (code !== 0) {
// GUI editors (VS Code, Zed, etc.) can exit with non-zero codes
// under normal circumstances (e.g., window closed while loading).
// Log a warning instead of crashing the CLI process.
debugLogger.warn(`${editor} exited with code ${code}`);
}
coreEvents.emit(CoreEvent.ExternalEditorClosed);
resolve();
});
childProcess.on('error', (error) => {
if (isSettled) return;
isSettled = true;
coreEvents.emit(CoreEvent.ExternalEditorClosed);
reject(error);
});
});