{"record":{"id":"69bea7d6df8ca160","repo":"iOfficeAI/AionUi","slug":"result-msg-fallbackmessage","errorCode":null,"errorMessage":"result?.msg || fallbackMessage","messagePattern":"result\\?\\.msg \\|\\| fallbackMessage","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/desktop/src/renderer/pages/conversation/platforms/assertBridgeSuccess.ts","lineNumber":24,"sourceCode":"    }\n  | null\n  | undefined;\n\nexport const assertBridgeSuccess = <T>(\n  result: BridgeResult<T>,\n  fallbackMessage: string\n): {\n  success: true;\n  data?: T;\n} => {\n  if (result?.success === true) {\n    return result as {\n      success: true;\n      data?: T;\n    };\n  }\n\n  throw new Error(result?.msg || fallbackMessage);\n};\n","sourceCodeStart":6,"sourceCodeEnd":26,"githubUrl":"https://github.com/iOfficeAI/AionUi/blob/711aa0550ee183ea495dc33e2c05c7943b70a60a/packages/desktop/src/renderer/pages/conversation/platforms/assertBridgeSuccess.ts#L6-L26","documentation":"`assertBridgeSuccess` narrows IPC bridge responses: when `result.success` is falsy (or result is undefined), it throws with the bridge-supplied `msg` or a caller-provided `fallbackMessage`. It converts silent backend failures into renderer-side exceptions.","triggerScenarios":"Any bridge call whose response has `success: false` — the backend rejected the operation (validation failure, missing config, permission denied) — or an undefined result because the handler crashed or returned nothing.","commonSituations":"Backend rejects a platform operation (e.g. missing credentials, invalid params); IPC handler threw and the wrapper swallowed it into a `{success:false, msg}` envelope; version skew where a newer renderer calls an older main-process handler that returns undefined.","solutions":["Inspect `result.msg` in the caught error — it usually carries the backend's rejection reason","Fix the underlying condition the backend reports (missing config, invalid input)","Confirm renderer and main-process versions match so the bridge envelope shape is consistent","If the handler can legitimately return undefined, guard upstream instead of relying on the fallback message"],"exampleFix":"// before\nconst result = await ipcBridge.someOp.invoke(payload);\nconst data = assertBridgeSuccess(result, 'op failed');\n\n// after (surface backend reason)\nconst result = await ipcBridge.someOp.invoke(payload);\nif (!result?.success) {\n  console.warn('op rejected:', result?.msg);\n}\nconst data = assertBridgeSuccess(result, 'op failed');","handlingStrategy":"try-catch","validationCode":"const result = await ipcBridge.op.invoke(payload);\nif (!result?.success) { /* read result.msg, fix precondition */ }","typeGuard":"type BridgeResult<T> = { success: true; data?: T } | { success: false; msg?: string };\nconst isBridgeOk = <T>(r: BridgeResult<T> | undefined): r is { success: true; data?: T } => !!r?.success;","tryCatchPattern":"try { const d = assertBridgeSuccess(await op()); } catch (e) { showError(e instanceof Error ? e.message : 'unknown'); }","preventionTips":["Always log result.msg when success is false","Version-lock renderer and main bridge envelope shapes"],"tags":["ipc","bridge","error-envelope","renderer"],"backgroundTag":"api-success-false-response","analyzedSha":"711aa0550ee183ea495dc33e2c05c7943b70a60a","analyzedAt":"2026-08-28T07:56:06.558Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}