Skip to content

fix(workspace): prevent unhandled rejection on missing workspace directory#1763

Merged
piorpua merged 2 commits intomainfrom
fix/sentry-ELECTRON-M
Mar 27, 2026
Merged

fix(workspace): prevent unhandled rejection on missing workspace directory#1763
piorpua merged 2 commits intomainfrom
fix/sentry-ELECTRON-M

Conversation

@kaizhou-lab
Copy link
Copy Markdown
Collaborator

Summary

  • Fix unhandled promise rejection when workspace directory is deleted (Sentry ELECTRON-M, 1397 events)
  • Move buildFileServer() inside try-catch in getWorkspace provider
  • Wrap copyFilesToDirectory in try-catch in sendMessage provider
  • Add null safety and .catch() to renderer-side workspace tree loading
  • Add unit tests for ENOENT error paths

Closes #1762

Test plan

  • Unit tests pass for getWorkspace ENOENT handling
  • Unit tests pass for sendMessage copyFilesToDirectory failure
  • Existing tests pass (135/135 test files, pre-existing dom test failure unrelated)
  • Type check passes (tsc --noEmit)
  • Lint passes (0 errors)

…ctory

The @office-ai/platform bridge library does not attach .catch() to
provider callback promises, so any rejection from an IPC provider
becomes an unhandled promise rejection in the main process.

When a user's workspace directory is deleted while a conversation
references it, fs.stat calls fail with ENOENT. This produced 1397
unhandled rejection events (Sentry ELECTRON-M).

Changes:
- Move buildFileServer() inside try-catch in getWorkspace provider
- Wrap copyFilesToDirectory in try-catch in sendMessage provider
- Add null safety check for res[0] in Workspace loadMore handler
- Add .catch() to loadWorkspace promise chain in useWorkspaceTree
- Add unit tests for ENOENT error paths

Fixes ELECTRON-M
@kaizhou-lab kaizhou-lab marked this pull request as ready for review March 26, 2026 14:20
@piorpua piorpua added bot:reviewing Review in progress (mutex) and removed bot:reviewing Review in progress (mutex) labels Mar 26, 2026
@piorpua piorpua added bot:reviewing Review in progress (mutex) and removed bot:reviewing Review in progress (mutex) labels Mar 26, 2026
@piorpua
Copy link
Copy Markdown
Contributor

piorpua commented Mar 27, 2026

Code Review:fix(workspace): prevent unhandled rejection on missing workspace directory (#1763)

变更概述

本 PR 修复了 Sentry 监控中频发(1397 次)的 unhandled promise rejection 问题(ELECTRON-M)。变更涉及三处:将 conversationBridge.ts 中的 buildFileServer() 调用移入 try-catch、为 copyFilesToDirectory 增加独立 try-catch、在 renderer 侧的工作区树加载链路补充 .catch() 处理器与 null 安全守卫。


方案评估

结论:✅ 方案合理

PR 对问题根因(bridge 层不为 provider promise 附加 .catch,导致 ENOENT 报错变成 unhandled rejection)的分析准确,修复位置正确。三处改动各自针对独立的调用路径,逻辑清晰,未引入不必要的复杂度,与项目已有的 try-catch 错误处理模式完全一致。


问题清单

🔵 LOW — sendMessage 的 catch 块捕获范围超出 ENOENT

文件src/process/bridge/conversationBridge.ts,第 417–422 行

问题代码

try {
  workspaceFiles = await copyFilesToDirectory(task.workspace, files, false, getSystemDir().cacheDir);
} catch (error) {
  console.error('[conversationBridge] sendMessage: failed to copy files to workspace:', error);
  workspaceFiles = [];
}

问题说明:catch 块捕获了所有错误类型(磁盘满、权限拒绝等),一律以空数组继续执行。相比之下,getWorkspace 的 catch 块对 ENOENT/aborted 做了细分。如果 copyFilesToDirectory 因非 ENOENT 原因失败(如磁盘满),用户附带的文件会被静默丢弃,消息仍照常发送。错误虽已 console.error 记录,但用户层面没有任何反馈。

修复建议(可选):该行为在 Electron 应用中基本合理(防崩溃优先于静默丢失文件),如需更严格,可在非 ENOENT 时向 sendMessage 传递一个 warn 标志,或至少上报文件丢失的指标。本问题不阻塞合并,保留现状亦可接受。


汇总

# 严重级别 文件 问题
1 🔵 LOW conversationBridge.ts:417 sendMessage catch 捕获所有错误,非 ENOENT 时文件静默丢失

结论

批准合并 — 修复方案正确,无阻塞性问题;测试覆盖了两个核心 ENOENT 路径,代码质量良好。


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

@piorpua
Copy link
Copy Markdown
Contributor

piorpua commented Mar 27, 2026

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

@piorpua piorpua merged commit 69a6ed1 into main Mar 27, 2026
17 checks passed
@piorpua piorpua deleted the fix/sentry-ELECTRON-M branch March 27, 2026 01:45
@piorpua piorpua added bot:done Auto-merged by bot and removed bot:reviewing Review in progress (mutex) labels Mar 27, 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 rejection on missing workspace directory (ELECTRON-M)

2 participants