Skip to content

fix(shellBridge): handle shell.openPath errors to prevent unhandled rejections#1806

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

fix(shellBridge): handle shell.openPath errors to prevent unhandled rejections#1806
piorpua merged 1 commit intomainfrom
fix/sentry-ELECTRON-C7

Conversation

@kaizhou-lab
Copy link
Copy Markdown
Collaborator

Summary

  • Wrap shell.openPath in try-catch to prevent unhandled promise rejections on Windows when no file association exists (error 0x483)
  • Also check the returned error string for non-throwing failure cases
  • Add 3 unit tests covering success, error-string, and rejection scenarios

Closes #1805
Fixes ELECTRON-C7

Sentry Details

Field Value
Issue ELECTRON-C7
Events 10
Release [email protected]
Platform Windows 10.0.26200
Last seen 6 hours ago

Test plan

  • Unit tests pass (bun run test -- tests/unit/shellBridge.test.ts)
  • TypeScript type check passes (bunx tsc --noEmit)
  • Lint passes (bun run lint:fix)
  • Format passes (bun run format)

…ejections

shell.openPath can reject on Windows when no application is associated
with the file type (error 0x483), producing an unhandled promise rejection
(Sentry ELECTRON-C7, 10 events on v1.9.1). Wrap in try-catch and also
check the returned error string for non-throwing failure cases.

Fixes ELECTRON-C7
@kaizhou-lab kaizhou-lab marked this pull request as ready for review March 27, 2026 12:19
@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(shellBridge): handle shell.openPath errors to prevent unhandled rejections (#1806)

变更概述

本 PR 修复了 Windows 上 shell.openPath 因文件无关联应用而触发未处理的 Promise rejection(Sentry 问题 ELECTRON-C7)。改动仅涉及 shellBridge.ts 和对应的单元测试文件,在原 await shell.openPath(path) 外包裹 try-catch,并同时处理返回错误字符串的非抛出失败场景。


方案评估

结论:✅ 方案合理

shell.openPath 存在两种失败模式:返回非空错误字符串(Electron 官方文档行为)和抛出 Promise rejection。两种情况均已正确处理,且与同文件中 openExternalconsole.warn 风格保持一致。新增 3 个单元测试覆盖全部分支,无过度工程化。


问题清单

🔵 LOW — (error as Error).message 类型断言可能导致日志输出 undefined

文件src/process/bridge/shellBridge.ts,第 18 行

问题代码

console.warn(`[shellBridge] Failed to open path:`, (error as Error).message);

问题说明:如果 shell.openPath 的 rejection 值不是 Error 实例(例如抛出的是字符串或普通对象),.message 会是 undefined,日志输出变为 "Failed to open path: undefined",诊断价值降低。Electron 的这个 API 在实践中会抛出 Error 对象,但强制类型断言并不安全。

修复建议

const msg = error instanceof Error ? error.message : String(error);
console.warn(`[shellBridge] Failed to open path:`, msg);

汇总

# 严重级别 文件 问题
1 🔵 LOW src/process/bridge/shellBridge.ts:18 (error as Error).message 断言不安全

结论

批准合并 — 无阻塞性问题,仅一个 LOW 级别日志健壮性建议,不影响功能正确性。


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

@piorpua
Copy link
Copy Markdown
Contributor

piorpua commented Mar 29, 2026

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

@piorpua piorpua merged commit 8f20d32 into main Mar 29, 2026
17 checks passed
@piorpua piorpua deleted the fix/sentry-ELECTRON-C7 branch March 29, 2026 07:09
@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(shellBridge): shell.openPath unhandled rejection on Windows (ELECTRON-C7)

2 participants