Skip to content

fix(settings): catch form validation rejection in EditModeModal#1779

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

fix(settings): catch form validation rejection in EditModeModal#1779
piorpua merged 1 commit intomainfrom
fix/sentry-ELECTRON-1E

Conversation

@kaizhou-lab
Copy link
Copy Markdown
Collaborator

Summary

  • Wrap EditModeModal's onOk handler in try-catch to prevent unhandled promise rejection when form validation fails
  • Add DOM test verifying no unhandled rejection occurs on validation failure

Closes #1778

Sentry: ELECTRON-1E (26 events, v1.9.1)

Verification

  • Unit tests pass: validation rejection is caught, onChange is not called
  • Type check passes (bunx tsc --noEmit)
  • Lint and format clean

Test plan

  • New test: validation failure does not produce unhandled rejection
  • New test: successful validation calls onChange with correct data
  • Existing tests unaffected

…handler

Wrap the onOk async handler in try-catch so that when Arco Form.validate()
rejects (user clicks Save with invalid fields), the rejection is caught
instead of surfacing as an unhandled promise rejection.

Fixes ELECTRON-1E
@kaizhou-lab kaizhou-lab marked this pull request as ready for review March 27, 2026 04:00
@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(settings): catch form validation rejection in EditModeModal (#1779)

变更概述

本 PR 为 EditModeModalonOk 回调新增了 try-catch 包裹,修复了 Arco Form validate() 在校验失败时抛出 rejection 导致的未处理 Promise 异常(Sentry ELECTRON-1E)。同时新增了一个 DOM 测试文件,验证校验失败不产生 unhandled rejection、校验成功正确调用 onChange


方案评估

结论:✅ 方案合理

修复方式最小且正确——Arco Form 在校验失败时会自动 reject,同时在 UI 上标红字段,因此空 catch 加注释是标准处理方式。测试覆盖了核心场景(失败不回调、成功正确回调)。无过度工程化,与项目架构完全一致。


问题清单

🔵 LOW — capturedOnOk 声明但未使用,触发 lint 警告

文件tests/unit/EditModeModal.dom.test.tsx,第 136 行

问题代码

let capturedOnOk: (() => Promise<void>) | undefined;
vi.mock('@/renderer/components/base/AionModal', () => ({
  default: ({ children, onOk, ...props }: any) => {
    capturedOnOk = onOk; // 赋值但从未读取

问题说明:该变量的初衷是"暴露 onOk 供直接调用",但实际测试改为通过 fireEvent.click 触发,capturedOnOk 从未被读取。oxlint 报 no-unused-vars 警告。

修复建议:将变量名前缀改为 _,或直接移除赋值语句(mock 仍可工作,onOk 已通过 onClick={onOk} 绑定)。


🔵 LOW — 第二个测试未移除 unhandledrejection 监听器

文件tests/unit/EditModeModal.dom.test.tsx,第 193–217 行

问题说明beforeEach 添加了监听器,第一个测试在结束时手动移除,但第二个测试未移除,导致监听器在测试完成后仍挂载。建议统一在 afterEach 中清理。

修复建议

afterEach(() => {
  window.removeEventListener('unhandledrejection', rejectionHandler);
});
// 并删除第一个测试中手动的 removeEventListener 调用

汇总

# 严重级别 文件 问题
1 🔵 LOW EditModeModal.dom.test.tsx:136 capturedOnOk 变量未使用,触发 lint 警告
2 🔵 LOW EditModeModal.dom.test.tsx:193 第二个测试未清理 unhandledrejection 监听器

结论

⚠️ 有条件批准 — 生产代码修复正确,两处均为测试文件的小问题,处理后可合并。


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

CONCLUSION: CONDITIONAL
IS_CRITICAL_PATH: false
PR_NUMBER: 1779

@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 29, 2026
@piorpua
Copy link
Copy Markdown
Contributor

piorpua commented Mar 29, 2026

PR Fix 验证报告

原始 PR: #1779
修复方式: 所有 review 问题均为 🔵 LOW 级别,已跳过(不阻塞合并)

# 严重级别 文件 问题 状态
1 🔵 LOW EditModeModal.dom.test.tsx:136 capturedOnOk 变量未使用,触发 lint 警告 ⏭️ 已跳过(LOW)
2 🔵 LOW EditModeModal.dom.test.tsx:193 第二个测试未清理 unhandledrejection 监听器 ⏭️ 已跳过(LOW)

总结: ✅ 已修复 0 个 | ⏭️ 跳过 2 个(均为 LOW)

🔵 LOW 级别问题已跳过(不阻塞合并,修复优先级低)。生产代码修复正确,可安全合并。

@piorpua piorpua merged commit 1fe108f into main Mar 29, 2026
17 checks passed
@piorpua piorpua deleted the fix/sentry-ELECTRON-1E branch March 29, 2026 05:19
@piorpua piorpua added bot:done Auto-merged by bot and removed bot:fixing Fix 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: unhandled form validation rejection in EditModeModal (ELECTRON-1E)

2 participants