fix(gemini): prevent unhandled rejection when bootstrap fails#1769
fix(gemini): prevent unhandled rejection when bootstrap fails#1769
Conversation
Attach no-op .catch() to the deferred bootstrap promise in both GeminiAgent (worker) and GeminiAgentManager (main process) constructors. Without this, when initialize() rejects (e.g. missing Google OAuth credentials), the rejection fires as an unhandledRejection before any caller awaits the promise — propagating to the renderer as a Sentry error. The error still surfaces when send() / sendMessage() later awaits bootstrap. Fixes ELECTRON-5B
Code Review:fix(gemini): prevent unhandled rejection when bootstrap fails (#1769)变更概述本 PR 修复了 Sentry issue ELECTRON-5B: 方案评估结论:✅ 方案合理
问题清单✅ 未发现明显问题,代码质量良好。 以下几点仅作信息说明(不影响合并): 测试文件中的时序假设( await new Promise((resolve) => setTimeout(resolve, 50));第一个测试用 50ms 等待来"给 Node 时间检测 unhandledRejection"。实际上 Node.js 在当前 microtask queue 耗尽后下一个 tick 即可确定 unhandled rejection,现有等待时间足够宽松,不构成实际 flaky 风险。 Lint 警告均为已有代码: 汇总本 PR 无需修复任何问题。 结论✅ 批准合并 — 修复方案正确、最小化,单元测试覆盖关键行为,CI 全部通过。 本报告由本地 |
|
✅ 已自动 review,无阻塞性问题,正在触发自动合并。 |
Summary
.catch(() => {})to the deferred bootstrap promise in bothGeminiAgent(worker) andGeminiAgentManager(main process) constructorsinitialize()rejects (e.g. missing Google OAuth credentials), the rejection no longer fires as anunhandledRejectionevent — the error still propagates whensend()/sendMessage()later awaits the promiseCloses #1768
Sentry issue: ELECTRON-5B (76 events, last seen today on v1.9.1)
Changed files
src/process/agent/gemini/index.ts.catch(() => {})afterthis.bootstrap = this.initialize()src/process/task/GeminiAgentManager.ts.catch(() => {})afterthis.bootstrap = this.createBootstrap()tests/unit/geminiBootstrapRejection.test.tsVerification
tsc --noEmit)previewFileWatch.dom.test.tsis unrelatedTest plan
bun run test— new tests passbunx tsc --noEmit— no type errors