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 <[email protected]>
This commit is contained in:
Cursor AgentandJulius Marminge committed 2026-02-09 05:23:09 +00:00
1 parent c8f33b89c6
commit 84b71e0a01
2 files changed
+13 -5

No files matched your search

+6 -1
View File
@@ -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();
},
);
+7 -4
View File
@@ -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<EditorId>(
() => (localStorage.getItem(LAST_EDITOR_KEY) as EditorId) ?? EDITORS[0].id,
);
const [lastEditor, setLastEditor] = useState<EditorId>(() => {
const stored = localStorage.getItem(LAST_EDITOR_KEY);
return EDITORS.some((e) => e.id === stored)
? (stored as EditorId)
: EDITORS[0].id;
});
const [selectedEffort, setSelectedEffort] =
useState<string>(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);
}
}