Skip to content

fix(openclaw): validate CLI binary exists before spawn to prevent ENOENT crash#1837

Merged
piorpua merged 3 commits intomainfrom
fix/sentry-ELECTRON-DZ
Mar 31, 2026
Merged

fix(openclaw): validate CLI binary exists before spawn to prevent ENOENT crash#1837
piorpua merged 3 commits intomainfrom
fix/sentry-ELECTRON-DZ

Conversation

@kaizhou-lab
Copy link
Copy Markdown
Collaborator

Summary

  • resolveCommandPath() now returns null instead of the bare command name when the CLI binary is not found on PATH
  • doStart() rejects early with a descriptive error before calling spawn(), preventing the fatal ENOENT crash
  • Added unit tests covering both missing and found CLI binary scenarios

Sentry: ELECTRON-DZ — 4 occurrences, fatal level, v1.9.1

Closes #1836

Test plan

  • Unit tests: CLI not found on PATH → rejects with clear error, spawn not called
  • Unit tests: absolute CLI path missing → rejects with clear error
  • Unit tests: CLI found on PATH → spawns correctly
  • bun run lint:fix — 0 errors
  • bunx tsc --noEmit — 0 errors
  • Pre-existing test failures in previewFileWatch.dom.test.ts are unrelated

…ENT crash

resolveCommandPath now returns null when the binary is not found instead
of falling back to the bare command name. doStart rejects early with a
descriptive error, preventing the unhandled spawn ENOENT that surfaced
as a fatal crash in Sentry (ELECTRON-DZ, 4 occurrences on v1.9.1).

Fixes ELECTRON-DZ
@kaizhou-lab kaizhou-lab marked this pull request as ready for review March 28, 2026 05:04
@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(openclaw): validate CLI binary exists before spawn to prevent ENOENT crash (#1837)

变更概述

本 PR 修改了 OpenClawGatewayManager.resolveCommandPath() 的返回类型(stringstring | null),当 CLI 二进制文件在 PATH 或绝对路径下不存在时返回 null,并在 doStart() 中提前检查并 reject,防止 spawn() 因 ENOENT 崩溃。新增了覆盖"CLI 未找到"和"CLI 正常启动"场景的单元测试。


方案评估

结论:✅ 方案合理

方案直接解决了 Sentry ELECTRON-DZ 报告的 ENOENT 崩溃问题,在 spawn 调用前进行预检是正确的防御策略。返回类型从 string 改为 string | null 符合语义,null 清晰表达"未找到",调用方被 TypeScript 强制处理 null 分支。实现简洁,无过度工程化,与项目现有代码风格一致。


问题清单

✅ 未发现明显问题,代码质量良好。

各维度检查结果:

  • 正确性:逻辑正确,绝对路径和 PATH 查找两条分支都正确处理了不存在的情况
  • 安全性:无安全风险
  • 不可变性:无对象变异
  • 错误处理:错误信息包含实际路径,有助于排查
  • 性能fs.accessSync 在启动路径上使用,可接受
  • 代码质量:改动聚焦,函数长度合理
  • console.log:无新增调试日志(已有的 console.log 为预存代码)
  • 测试:覆盖了三个关键场景(PATH 查找失败、绝对路径不存在、正常启动),mock 设置正确,跨平台兼容

汇总

无问题。

结论

  • 批准合并 — 改动聚焦、方案合理、测试充分,无阻塞性问题。

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

CONCLUSION: APPROVED
IS_CRITICAL_PATH: false
PR_NUMBER: 1837

@piorpua piorpua added bot:ci-waiting CI failed and author notified — snoozed until new commits are pushed and removed bot:reviewing Review in progress (mutex) labels Mar 29, 2026
@piorpua piorpua added bot:reviewing Review in progress (mutex) and removed bot:ci-waiting CI failed and author notified — snoozed until new commits are pushed labels Mar 31, 2026
@piorpua
Copy link
Copy Markdown
Contributor

piorpua commented Mar 31, 2026

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

@piorpua piorpua merged commit c913210 into main Mar 31, 2026
30 checks passed
@piorpua piorpua deleted the fix/sentry-ELECTRON-DZ branch March 31, 2026 07:02
@piorpua piorpua added bot:done Auto-merged by bot and removed bot:reviewing Review in progress (mutex) labels Mar 31, 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(openclaw): spawn ENOENT crash when openclaw CLI not found (ELECTRON-DZ)

2 participants