Skip to content

fix(alerts): surface the validation reason when a silence cannot be built - #4285

Closed
unbridled-41 wants to merge 1 commit into
apache:rocketmq-studiofrom
unbridled-41:fix/silence-validation-message-surfaced
Closed

unbridled-41 wants to merge 1 commit into
apache:rocketmq-studiofrom
unbridled-41:fix/silence-validation-message-surfaced

Conversation

@unbridled-41

@unbridled-41 unbridled-41 commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #4282.

Problem / Evidence

维护窗口创建弹窗(systemAlerts.tsx 的 createSilence)把请求构造(纯客户端校验)与 API 调用包在同一个 try 中,唯一 catch 只显示通用 toast sysAlerts.silenceCreateFailed:

  • parseSilenceLabels 对任何无 = 片段 throw new Error(invalidMessage)(含尾逗号 a=1, 这种高频输入,split 产生空片段),invalidMessage 即专用文案 sysAlerts.labelsFormatInvalid("标签格式应为 key=value,并以逗号分隔")——该 i18n key 在此路径下不可达(死代码);
  • recurring 窗口的时区字段只校验非空,GMT+8 类非 IANA 输入时 zonedLocalDateTimeToUtc 抛出的具体错误同样被吞;
  • 这些异常发生在任何 HTTP 请求之前,axios 拦截器不会兜底展示,用户对失败原因零感知、无字段指向。回归测试先红: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 全绿。
  • 全量 web(分支上两轮 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 eslint 0 error(systemAlerts.tsx:227 的 exhaustive-deps warning 为基线既有、不在改动 hunk);npm run build ✓(10.45s)。
  • numstat 自检:systemAlerts.tsx +14/−1、SystemAlertsPage.test.tsx +23/−0。

Risk

低。仅调整校验异常的展示路径;API 调用、成功路径、loading 状态管理均不变。CI:upstream 工作流全部 startup_failure(0 check-runs),head 59b36f6 无 CI 结果,以上为本地完整验证。

…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.
@unbridled-41

unbridled-41 commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor Author

Verification evidence

  • CI:head 59b36f68 恰有一条 CI (pull_request) run —— id 34772506551,conclusion=startup_failure、0 check-runs(与基线一致,非本变更引起)。
  • 红灯(实际输出):npx vitest run src/pages/ops/__tests__/SystemAlertsPage.test.tsx → Tests 1 failed | 14 passed (15),失败项 surfaces the label validation message when the silence labels are invalid(专用消息未出现,仅通用 toast)。
  • 模块:修复后 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 eslint(两改动文件)0 error,systemAlerts.tsx:227 的 exhaustive-deps warning 为基线既有且不在改动 hunk;npm run build ✓ 10.45s。
  • Diff 自检(numstat):web/src/pages/ops/systemAlerts.tsx +14/−1、web/src/pages/ops/__tests__/SystemAlertsPage.test.tsx +23/−0;仅 2 文件,无无关改动。

@RockteMQ-AI RockteMQ-AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. The changes look good.


Automated review by github-manager-bot

@unbridled-41

Copy link
Copy Markdown
Contributor Author

复测实证(应用户要求对缺陷做最终实测)

在干净 worktree(pristine 6c24d2e)上重新做了两层验证:

① 基线复现(只带本 PR 回归测试 + 基线源码):

npx vitest run src/pages/ops/__tests__/SystemAlertsPage.test.tsx
× surfaces the label validation message when the silence labels are invalid
Tests  2 failed | 22 passed (24)   ← 同批含 #4283 用例,另一失败为其同款

(断言期望出现专用校验消息「标签格式应为 key=value,并以逗号分隔」,实际只有通用 toast——与 Issue 描述一致。)

② 修复解除(仅替换 systemAlerts.tsx 为修复版):

Test Files  2 passed (2) / Tests  24 passed (24)

③ 无兜底主张核实:createAlertSilence(HTTP 调用)仅在请求构造成功后才被调用——校验异常抛出点(parseSilenceLabels / zonedLocalDateTimeToUtc)先于任何请求,axios 拦截器无从展示;回归测试同时断言 createAlertSilence 未被调用。失败确为"零指向的死路"。

@RockteMQ-AI RockteMQ-AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Info] Moving request declaration outside the try block and separating validation from API call is the right pattern. This ensures:

  1. Validation errors (thrown during request construction) are caught and displayed with their specific messages
  2. The axios interceptor never sees these errors, so field-specific messages aren't lost
  3. 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 () => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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 createAlertSilence was NOT called (validation happens client-side)

This test would have caught the original bug where the validation message was unreachable.

@RockteMQ-AI RockteMQ-AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 request variable 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

lizhimins pushed a commit that referenced this pull request Sep 16, 2026
#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
@lizhimins

Copy link
Copy Markdown
Member

Merged as part of #4331 — squashed into rocketmq-studio as 6334f9238.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants