Repository navigation
fix(alerts): surface the validation reason when a silence cannot be built - #4285
unbridled-41 wants to merge 1 commit into
Conversation
…uilt The silence dialog built the request and called the API inside one try whose catch only showed the generic "creation failed" toast, so the purpose-built messages from parseSilenceLabels and the timezone conversion were unreachable — a trailing comma in the label scope (or an unparseable time zone) blocked creation with no pointer to the field. Build the request first and surface the client-side error message; API failures keep the generic toast on top of the interceptor's report.
Verification evidence
|
RockteMQ-AI
left a comment
There was a problem hiding this comment.
LGTM. The changes look good.
Automated review by github-manager-bot
复测实证(应用户要求对缺陷做最终实测)在干净 worktree(pristine 6c24d2e)上重新做了两层验证: ① 基线复现(只带本 PR 回归测试 + 基线源码): (断言期望出现专用校验消息「标签格式应为 key=value,并以逗号分隔」,实际只有通用 toast——与 Issue 描述一致。) ② 修复解除(仅替换 systemAlerts.tsx 为修复版): ③ 无兜底主张核实: |
RockteMQ-AI
left a comment
There was a problem hiding this comment.
Summary
This PR fixes a UX bug where client-side validation errors in the maintenance window creation form were being swallowed by a single catch block, preventing users from seeing field-specific error messages. The fix cleanly separates validation from API calls.
Findings
- [Info] systemAlerts.tsx:402 — Correct pattern: separate validation try/catch from API try/catch
- [Info] SystemAlertsPage.test.tsx:550 — Regression test covers the exact failure mode
Strengths
✅ Minimal, focused change (+14/-1 in main file)
✅ Preserves existing API error handling semantics
✅ Activates previously dead i18n key (sysAlerts.labelsFormatInvalid)
✅ Comprehensive test coverage with realistic edge case (trailing comma)
✅ PR description thoroughly documents the problem, root cause, and verification
Verification
The PR description shows:
- Regression test initially failed (red), then passed after fix (green)
- Full test suite: 982 tests, 2 pre-existing flaky tests in untouched files
- TypeScript, ESLint, and build all pass cleanly
This is a well-executed bug fix with excellent documentation and test coverage.
| return; | ||
| } | ||
| setSavingSilence(true); | ||
| let request: CreateAlertSilence; |
There was a problem hiding this comment.
[Info] Moving request declaration outside the try block and separating validation from API call is the right pattern. This ensures:
- Validation errors (thrown during request construction) are caught and displayed with their specific messages
- The axios interceptor never sees these errors, so field-specific messages aren't lost
- No HTTP request is made when validation fails
The fallback to t('sysAlerts.silenceCreateFailed') when error.message is empty is a good safety net.
| }); | ||
| }); | ||
|
|
||
| it('surfaces the label validation message when the silence labels are invalid', async () => { |
There was a problem hiding this comment.
[Info] The regression test is well-constructed:
- Uses a trailing comma (
brokerName=broker-a,) which is a realistic user mistake - Asserts the specific validation message appears
- Verifies
createAlertSilencewas NOT called (validation happens client-side)
This test would have caught the original bug where the validation message was unreachable.
RockteMQ-AI
left a comment
There was a problem hiding this comment.
Summary
This PR fixes a bug where validation errors from the silence creation form were not properly surfaced to the user. The fix correctly separates client-side validation errors from API errors by splitting the try-catch into two blocks.
The implementation is clean:
- Moves the
requestvariable declaration outside the first try block - Catches validation errors separately and displays the specific error message
- Falls back to the generic error message if the error has no message
- Includes a test case that verifies the label validation message is shown
LGTM. Good fix with proper test coverage.
Automated review by github-manager
#4331) Incorporates ten related front-end fixes from the same author: - #4175 render the rule last-triggered time as UTC - #4189 keep the selected range when the metrics instance changes - #4245 reload the paginated group list after creating groups - #4249 edit topic configuration from the topic page - #4254 reset the silence form when the maintenance dialog is dismissed - #4263 export users against the committed search term - #4265 re-run the custom query when the dashboard instance changes - #4283 reset the queue browser pull indicators when the queue list reloads - #4285 surface the validation reason when a silence cannot be built - #4322 invalidate the in-flight connection query when the topic changes
|
Merged as part of #4331 — squashed into Your change here (surfacing the label validation reason when a silence cannot be built) is included. We grouped 11 of your related front-end fixes into a single commit so the history stays reviewable; the other PRs in the group are closed with the same note. Everything was cherry-picked onto the current baseline with you kept as the author, and your tests came along with the change. Thanks for the consistently well-tested patches. |
Fixes #4282.
Problem / Evidence
维护窗口创建弹窗(
systemAlerts.tsx的createSilence)把请求构造(纯客户端校验)与 API 调用包在同一个try中,唯一catch只显示通用 toastsysAlerts.silenceCreateFailed:parseSilenceLabels对任何无=片段throw new Error(invalidMessage)(含尾逗号a=1,这种高频输入,split 产生空片段),invalidMessage即专用文案sysAlerts.labelsFormatInvalid("标签格式应为 key=value,并以逗号分隔")——该 i18n key 在此路径下不可达(死代码);GMT+8类非 IANA 输入时zonedLocalDateTimeToUtc抛出的具体错误同样被吞;surfaces the label validation message when the silence labels are invalid(断言专用消息出现且createAlertSilence未被调用)。Root cause / Fix
单一 catch 无法区分"客户端校验抛出的专用消息"与"API 失败"(axios 拦截器对业务码错误也 reject 普通 Error,instanceof 无法区分)。修复:把请求构造拆到独立 try,在catch 中显示
error.message(无消息时回退通用文案)后直接返回;API 调用保持原 try/catch/finally 语义不变(+14/−1)。Priority & scoring
PRIORITY 70 = 影响 28(告警降噪核心操作被无指向失败硬性卡死,尾逗号即触发、重试无出路;对比 #4241 的服务端原因尚有拦截器兜底,本缺陷完全无兜底)+ 波及 10(单弹窗单流程)+ 可复现 18(确定性 UI 序列)+ 维护价值 14(恢复既有专用校验消息契约,激活死 i18n key);FIX_CONFIDENCE 96(先红后绿,逻辑拆分无行为变化)。
Tests
npx vitest run src/pages/ops/__tests__/SystemAlertsPage.test.tsx→Tests 1 failed | 14 passed (15);修复后 15/15 全绿。npx vitest run):982 tests(pristine 6c24d2e = 981 + 本 PR 新增 1),每轮 2 failed 且集合轮换(第一轮 tail 仅记录 2 failed|980 passed 未留文件名;第二轮经输出确认为 AclPage×1「uses Tencent role names...」+ConsumerPage×1「shows group health diagnostics...」——历轮记录的未触碰文件负载脆弱族),两失败文件隔离复跑 54/54 通过;本 PR 触碰文件的套件在两轮全量中均全过。npx tsc -b干净;npx eslint0 error(systemAlerts.tsx:227 的 exhaustive-deps warning 为基线既有、不在改动 hunk);npm run build✓(10.45s)。systemAlerts.tsx +14/−1、SystemAlertsPage.test.tsx +23/−0。Risk
低。仅调整校验异常的展示路径;API 调用、成功路径、loading 状态管理均不变。CI:upstream 工作流全部 startup_failure(0 check-runs),head 59b36f6 无 CI 结果,以上为本地完整验证。