Skip to content

Commit f364d8c

Browse files
authored
🤖 Fix browser API handling of failed Results without error property (#393)
_Generated with `cmux`_ ## Problem The web main-server's `HttpIpcMainAdapter` was incorrectly handling failed Results that don't have an `error` property. The check required both `success === false` AND `'error' in result`: ```typescript if ( result && typeof result === "object" && "success" in result && result.success === false && "error" in result // <-- This line was the bug ) { res.json(result); return; } res.json({ success: true, data: result }); ``` When a handler returned `{ success: false }` without an `error` property, the check failed and the result was incorrectly wrapped as: ```json { "success": true, "data": { "success": false } } ``` This broke error handling in the frontend - errors from operations like force workspace deletion weren't being properly communicated. ## Solution Remove the `'error' in result` requirement. Any Result with `success: false` should be passed through directly, regardless of whether it has an `error` property. ## Testing Added test case in `api.test.ts` to verify Results without error property are handled correctly.
1 parent 181a2e9 commit f364d8c

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

‎src/browser/api.test.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,25 @@ describe("Browser API invokeIPC", () => {
132132
error: structuredError,
133133
});
134134
});
135+
136+
test("should handle failed Result without error property", async () => {
137+
// This tests the fix for the force-deletion bug where results like
138+
// { success: false } (without error property) weren't being passed through correctly
139+
const mockFetch = createMockFetch({
140+
success: false,
141+
});
142+
143+
const invokeIPC = createInvokeIPC(mockFetch);
144+
145+
const result = await invokeIPC<{ success: boolean; error?: string }>(
146+
"WORKSPACE_REMOVE",
147+
"test-workspace",
148+
{ force: false }
149+
);
150+
151+
// Should return the failure result as-is, even without error property
152+
expect(result).toEqual({
153+
success: false,
154+
});
155+
});
135156
});

‎src/main-server.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ class HttpIpcMainAdapter {
3636
result &&
3737
typeof result === "object" &&
3838
"success" in result &&
39-
result.success === false &&
40-
"error" in result
39+
result.success === false
4140
) {
4241
// Pass through failed Result to preserve error structure
4342
res.json(result);

0 commit comments

Comments
 (0)