Skip to content

fix(fsBridge): handle EBUSY in readFile/readFileBuffer#1754

Merged
piorpua merged 2 commits intomainfrom
fix/sentry-ELECTRON-D1
Mar 26, 2026
Merged

fix(fsBridge): handle EBUSY in readFile/readFileBuffer#1754
piorpua merged 2 commits intomainfrom
fix/sentry-ELECTRON-D1

Conversation

@kaizhou-lab
Copy link
Copy Markdown
Collaborator

Summary

  • Handle EBUSY error in readFile and readFileBuffer providers by returning null instead of re-throwing
  • Windows file locks (e.g., open .pptx files) cause EBUSY, which was previously unhandled

Sentry: ELECTRON-D1 (283 occurrences)

Closes #1753

Test plan

  • Unit tests: readFile returns null for EBUSY
  • Unit tests: readFileBuffer returns null for EBUSY
  • Unit tests: other errors (EPERM) still throw
  • Type check passes
  • Lint passes

…ning null

When a file is locked by another process (common on Windows), fs.readFile
throws EBUSY. The catch block only handled ENOENT, causing EBUSY to become
an unhandled promise rejection.

Return null for EBUSY, consistent with ENOENT handling for inaccessible files.

Fixes ELECTRON-D1
@kaizhou-lab kaizhou-lab marked this pull request as ready for review March 26, 2026 12:27
@piorpua piorpua added the bot:reviewing Review in progress (mutex) label Mar 26, 2026
@piorpua
Copy link
Copy Markdown
Contributor

piorpua commented Mar 26, 2026

Code Review:fix(fsBridge): handle EBUSY in readFile/readFileBuffer (#1754)

变更概述

本 PR 修复了 Windows 文件系统中 EBUSY(资源忙/被锁定)错误未被处理的问题。在 fsBridge.tsreadFilereadFileBuffer provider 中,将 EBUSY 与已有的 ENOENT 并列处理,返回 null 而非抛出异常,同时新增单元测试验证三种场景。另包含 @office-ai/aioncli-core 版本从 0.30.1 升级至 0.30.2(关联的上游修复)。


方案评估

结论:✅ 方案合理

EBUSYENOENT 统一处理(均返回 null)的语义是合理的:二者都代表当前无法读取该文件,而不是系统级错误。变量提取(const code = ...)消除了重复类型转换,代码更简洁。方案与现有架构完全一致,无过度工程化。


问题清单

🔵 LOW — 测试文件:未使用的 Mock 类型导入

文件tests/unit/process/bridge/fsBridge.readFile.test.ts,第 2 行

问题代码

import type { Mock } from 'vitest';

问题说明Mock 类型从未被使用,oxlint 已报出 no-unused-vars 警告。

修复建议:删除此行。


🔵 LOW — 测试文件:辅助函数作用域可提升

文件tests/unit/process/bridge/fsBridge.readFile.test.ts,第 117、122 行

问题代码

async function setupProviders() { ... }
function makeErrnoError(...) { ... }

问题说明:两个函数均未捕获 describe 闭包内的任何变量,但定义在 describe 块内,oxlint 报出 consistent-function-scoping 警告。

修复建议:将两个函数移至 describe 块外部(文件作用域)。


汇总

# 严重级别 文件 问题
1 🔵 LOW fsBridge.readFile.test.ts:2 未使用的 Mock 导入
2 🔵 LOW fsBridge.readFile.test.ts:117,122 辅助函数可移至外层作用域

结论

批准合并 — 无阻塞性问题

核心修复逻辑正确,测试覆盖 EBUSY/ENOENT/其他错误/成功读取四种场景,所有 CI 检查通过。仅两处 LOW 级别的 lint 警告在测试文件中,不影响正确性。


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

@piorpua piorpua added bot:ready-to-fix CONDITIONAL review done, waiting for bot fix bot:fixing Fix in progress (mutex) and removed bot:reviewing Review in progress (mutex) bot:ready-to-fix CONDITIONAL review done, waiting for bot fix labels Mar 26, 2026
- Remove unused Mock type import from vitest
- Move setupProviders and makeErrnoError to file scope

Review follow-up for #1754
@piorpua
Copy link
Copy Markdown
Contributor

piorpua commented Mar 26, 2026

PR Fix 验证报告

原始 PR: #1754
修复方式: 直接推送到 fix/sentry-ELECTRON-D1

# 严重级别 文件 问题 修复方式 状态
1 🔵 LOW fsBridge.readFile.test.ts:2 未使用的 Mock 类型导入 删除 import type { Mock } from 'vitest' 整行 ✅ 已修复
2 🔵 LOW fsBridge.readFile.test.ts:117,122 辅助函数作用域可提升 setupProvidersmakeErrnoError 移至 describe 块外部(文件作用域) ✅ 已修复

总结: ✅ 已修复 2 个 | ❌ 未能修复 0 个

@piorpua piorpua added bot:done Auto-merged by bot and removed bot:fixing Fix in progress (mutex) labels Mar 26, 2026
@piorpua piorpua merged commit 861eb4b into main Mar 26, 2026
17 checks passed
@piorpua piorpua deleted the fix/sentry-ELECTRON-D1 branch March 26, 2026 13:24
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: handle EBUSY in fsBridge readFile/readFileBuffer

2 participants