@@ -42,14 +42,10 @@ function createInvokeIPC(
4242
4343 const result = ( await response . json ( ) ) as InvokeResponse < T > ;
4444
45+ // Return the result as-is - let the caller handle success/failure
46+ // This matches the behavior of Electron's ipcRenderer.invoke() which doesn't throw on error
4547 if ( ! result . success ) {
46- // Failed response - check if it's a structured error or simple string
47- if ( typeof result . error === "object" && result . error !== null ) {
48- // Structured error (e.g., SendMessageError) - return as Result<T, E> for caller to handle
49- return result as T ;
50- }
51- // Simple string error - throw it
52- throw new Error ( typeof result . error === "string" ? result . error : "Unknown error" ) ;
48+ return result as T ;
5349 }
5450
5551 // Success - unwrap and return the data
@@ -60,31 +56,16 @@ function createInvokeIPC(
6056}
6157
6258describe ( "Browser API invokeIPC" , ( ) => {
63- test ( "CURRENT BEHAVIOR: throws on string error (causes unhandled rejection )" , async ( ) => {
59+ test ( "should return error object on failure (matches Electron behavior )" , async ( ) => {
6460 const mockFetch = createMockFetch ( {
6561 success : false ,
6662 error : "fatal: contains modified or untracked files" ,
6763 } ) ;
6864
6965 const invokeIPC = createInvokeIPC ( mockFetch ) ;
7066
71- // Current behavior: invokeIPC throws on string errors
72- // eslint-disable-next-line @typescript-eslint/await-thenable
73- await expect ( invokeIPC ( "WORKSPACE_REMOVE" , "test-workspace" , { force : false } ) ) . rejects . toThrow (
74- "fatal: contains modified or untracked files"
75- ) ;
76- } ) ;
77-
78- test . skip ( "DESIRED BEHAVIOR: should return error object on string error (match Electron)" , async ( ) => {
79- const mockFetch = createMockFetch ( {
80- success : false ,
81- error : "fatal: contains modified or untracked files" ,
82- } ) ;
83-
84- const invokeIPC = createInvokeIPC ( mockFetch ) ;
85-
86- // Desired behavior: Should return { success: false, error: "..." }
87- // This test documents what we want - actual implementation test is below
67+ // Fixed behavior: invokeIPC returns error object instead of throwing
68+ // This matches Electron's ipcRenderer.invoke() which never throws on error
8869 const result = await invokeIPC < { success : boolean ; error ?: string } > (
8970 "WORKSPACE_REMOVE" ,
9071 "test-workspace" ,
0 commit comments