Skip to content

fix(fsBridge): prevent unhandled rejection in downloadRemoteBuffer#1825

Merged
piorpua merged 1 commit intomainfrom
fix/sentry-ELECTRON-77
Mar 29, 2026
Merged

fix(fsBridge): prevent unhandled rejection in downloadRemoteBuffer#1825
piorpua merged 1 commit intomainfrom
fix/sentry-ELECTRON-77

Conversation

@kaizhou-lab
Copy link
Copy Markdown
Collaborator

Summary

Closes #1824 — Fixes Sentry ELECTRON-77 (96 occurrences).

  • Replace Promise.reject() with throw in downloadRemoteBuffer for URL validation errors (unsupported protocol, disallowed host)
  • This prevents unhandled promise rejections when the IPC handler is invoked through the event emitter adapter path that does not await the async handler's returned promise

Changes

  • src/process/bridge/fsBridge.ts: Changed 2 return Promise.reject(new Error(...))throw new Error(...)
  • tests/unit/process/bridge/fsBridge.downloadRemoteBuffer.test.ts: Added tests verifying disallowed host, unsupported protocol, and invalid URL all return empty string gracefully

Test plan

  • New unit tests pass: disallowed host, unsupported protocol, invalid URL
  • Existing fsBridge tests pass
  • TypeScript type check passes
  • Lint and format clean
  • Manual verification: the error no longer appears as unhandled rejection in production

…ed rejections

Fixes ELECTRON-77. The downloadRemoteBuffer function used Promise.reject()
for URL validation errors, which could surface as unhandled promise rejections
when the IPC bridge handler was invoked through an event emitter that does not
await the returned promise. Using throw instead ensures the error is caught
synchronously by the caller's try-catch.
@kaizhou-lab kaizhou-lab marked this pull request as ready for review March 28, 2026 03:01
@piorpua piorpua added the bot:reviewing Review in progress (mutex) label Mar 29, 2026
@piorpua
Copy link
Copy Markdown
Contributor

piorpua commented Mar 29, 2026

Code Review:fix(fsBridge): prevent unhandled rejection in downloadRemoteBuffer (#1825)

变更概述

本 PR 修复 Sentry 问题 ELECTRON-77(96 次出现),将 downloadRemoteBuffer 函数中两处 return Promise.reject(new Error(...)) 改为 throw new Error(...)。同时新增单测文件,覆盖禁止域名、不支持协议、非法 URL 三种场景。


方案评估

结论:✅ 方案合理

downloadRemoteBuffer 是一个同步函数(非 async),直接 throwreturn Promise.reject() 更安全:throw 是同步抛出,由调用方 async 函数的 try/catch 直接捕获;而 return Promise.reject() 创建一个待处理的 rejected Promise 对象,若 IPC event emitter 适配器路径未 await 该 Promise,就可能产生 unhandled rejection。修改简洁直接,与项目已有架构一致。


问题清单

未发现任何新引入问题。lint 输出中出现的 no-await-in-loop 警告均为文件中已存在的历史问题(与本次改动无关),不计入本次 review。


汇总

无问题。

结论

批准合并 — 改动正确、简洁,测试覆盖充分,无阻塞性问题。


本报告由本地 pr-review skill 生成,包含完整项目上下文,无截断限制。

CONCLUSION: APPROVED
IS_CRITICAL_PATH: false
PR_NUMBER: 1825

@piorpua
Copy link
Copy Markdown
Contributor

piorpua commented Mar 29, 2026

✅ 已自动 review,无阻塞性问题,正在触发自动合并。

@piorpua piorpua merged commit c9b0ed5 into main Mar 29, 2026
17 checks passed
@piorpua piorpua deleted the fix/sentry-ELECTRON-77 branch March 29, 2026 08:22
@piorpua piorpua added bot:done Auto-merged by bot and removed bot:reviewing Review in progress (mutex) labels Mar 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:done Auto-merged by bot

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: unhandled promise rejection in downloadRemoteBuffer (ELECTRON-77)

2 participants