mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-31 08:20:54 -07:00
fix(core): handle GUI editor non-zero exit codes gracefully (#20376)
Co-authored-by: Jacob Richman <jacob314@gmail.com>
This commit is contained in:
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user