From 84b71e0a016acc71cf12e375a2b151ee20bc11b3 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 9 Feb 2026 05:23:09 +0000 Subject: [PATCH] fix: add error handling and address review feedback - Validate cwd is non-empty in shell:open-in-editor IPC handler - Check shell.openPath() return value and throw on error - Attach spawn error listener to prevent crashes from missing CLI - Validate localStorage lastEditor against known EDITORS list - Only call preventDefault() for Cmd+O when action will run Co-authored-by: Julius Marminge --- apps/desktop/src/main.ts | 7 ++++++- apps/renderer/src/components/ChatView.tsx | 11 +++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/apps/desktop/src/main.ts b/apps/desktop/src/main.ts index 7c2ce9baa8..868219fe68 100644 --- a/apps/desktop/src/main.ts +++ b/apps/desktop/src/main.ts @@ -130,16 +130,21 @@ function registerIpcHandlers(): void { ipcMain.handle( IPC_CHANNELS.shellOpenInEditor, async (_event, cwd: string, editor: string) => { + if (!cwd) throw new Error("cwd is required"); const editorDef = EDITORS.find((e) => e.id === editor); if (!editorDef) throw new Error(`Unknown editor: ${editor}`); if (!editorDef.command) { - await shell.openPath(cwd); + const error = await shell.openPath(cwd); + if (error) throw new Error(error); return; } const child = spawn(editorDef.command, [cwd], { detached: true, stdio: "ignore", }); + child.on("error", () => { + /* ignore spawn failures for detached editors */ + }); child.unref(); }, ); diff --git a/apps/renderer/src/components/ChatView.tsx b/apps/renderer/src/components/ChatView.tsx index a668510de5..56d996f23a 100644 --- a/apps/renderer/src/components/ChatView.tsx +++ b/apps/renderer/src/components/ChatView.tsx @@ -65,9 +65,12 @@ export default function ChatView() { const [isConnecting, setIsConnecting] = useState(false); const [isModelMenuOpen, setIsModelMenuOpen] = useState(false); const [isEditorMenuOpen, setIsEditorMenuOpen] = useState(false); - const [lastEditor, setLastEditor] = useState( - () => (localStorage.getItem(LAST_EDITOR_KEY) as EditorId) ?? EDITORS[0].id, - ); + const [lastEditor, setLastEditor] = useState(() => { + const stored = localStorage.getItem(LAST_EDITOR_KEY); + return EDITORS.some((e) => e.id === stored) + ? (stored as EditorId) + : EDITORS[0].id; + }); const [selectedEffort, setSelectedEffort] = useState(DEFAULT_REASONING); const [nowTick, setNowTick] = useState(() => Date.now()); @@ -185,8 +188,8 @@ export default function ChatView() { useEffect(() => { const handler = (e: globalThis.KeyboardEvent) => { if (e.key === "o" && (e.metaKey || e.ctrlKey) && !e.shiftKey) { - e.preventDefault(); if (api && activeProject) { + e.preventDefault(); void api.shell.openInEditor(activeProject.cwd, lastEditor); } }