Skip to content

fix(snapshot): return empty array from getBranches in snapshot mode#1982

Merged
piorpua merged 1 commit intomainfrom
fix/sentry-ELECTRON-G8
Mar 31, 2026
Merged

fix(snapshot): return empty array from getBranches in snapshot mode#1982
piorpua merged 1 commit intomainfrom
fix/sentry-ELECTRON-G8

Conversation

@kaizhou-lab
Copy link
Copy Markdown
Collaborator

Summary

  • getBranches called ensureGitRepo which throws when the workspace is in snapshot mode, causing an unhandled promise rejection (Sentry ELECTRON-G8, 5 events, 2 on v1.9.4)
  • Changed getBranches to check snapshot state inline and return [] for non-git-repo workspaces instead of throwing
  • Added unit tests for getBranches in both snapshot and uninitialised workspace scenarios

Test plan

  • Unit tests pass (WorkspaceSnapshotService.test.ts — 30/30 passing)
  • Verify no unhandled rejection in Sentry after deployment

getBranches called ensureGitRepo which throws when the workspace is in
snapshot mode. The renderer calls getBranches regardless of mode,
causing an unhandled promise rejection (ELECTRON-G8, 5 events, 2 on
v1.9.4). Return [] instead of throwing for non-git-repo workspaces.
@kaizhou-lab kaizhou-lab marked this pull request as ready for review March 31, 2026 07:40
@piorpua piorpua added the bot:reviewing Review in progress (mutex) label Mar 31, 2026
@piorpua
Copy link
Copy Markdown
Contributor

piorpua commented Mar 31, 2026

Code Review:fix(snapshot): return empty array from getBranches in snapshot mode (#1982)

变更概述

本 PR 修复了 WorkspaceSnapshotService.getBranches() 在 snapshot 模式或未初始化工作区下调用 ensureGitRepo() 抛出异常导致 unhandled promise rejection 的问题(Sentry ELECTRON-G8)。改为内联检查状态后返回空数组,并新增了两个对应的单元测试。


方案评估

结论:✅ 方案合理

修改将 getBranches 从抛出异常改为优雅降级返回空数组,与同类中 compare()getBaselineContent()getInfo() 对缺失状态的处理方式完全一致。条件判断 !state || state.mode !== 'git-repo' 精确覆盖了未初始化和 snapshot 两种场景,无设计盲点。


问题清单

✅ 未发现明显问题,代码质量良好,建议批准合并。


汇总

无问题。

结论

  • 批准合并 — 修复逻辑正确,与已有模式一致,测试覆盖充分。

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

CONCLUSION: APPROVED
IS_CRITICAL_PATH: false
PR_NUMBER: 1982

@piorpua
Copy link
Copy Markdown
Contributor

piorpua commented Mar 31, 2026

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

@piorpua piorpua merged commit c843723 into main Mar 31, 2026
17 checks passed
@piorpua piorpua deleted the fix/sentry-ELECTRON-G8 branch March 31, 2026 10:59
@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.

2 participants