Skip to content

fix: send specific messageKey for FailedPrecondition errors to frontend - #2780

Open
t-kikuc wants to merge 3 commits into
mainfrom
fix/i18n-messagekey-override
Open

fix: send specific messageKey for FailedPrecondition errors to frontend#2780
t-kikuc wants to merge 3 commits into
mainfrom
fix/i18n-messagekey-override

Conversation

@t-kikuc

@t-kikuc t-kikuc commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Refs #1253

What this PR does

Adds a messageKeyOverride mechanism to BktError so that FailedPrecondition (and other generic-type) errors can send a specific i18n key to the frontend instead of the generic error type string.

Background

After the i18n migration (#1253), BktError.MessageKey() always returned string(errorType) (e.g., "FailedPreconditionError"). This worked for InvalidArgument errors because the field metadata differentiates them, but all FailedPrecondition errors shared the same messageKey and displayed the same generic message.

The frontend already had specific translation keys (e.g., "CommentRequiredForUpdating", "SegmentInUse", "InvalidArchive"), but the backend never sent them. This PR connects the two.

Before / After examples

All FailedPrecondition errors showed the same generic message:

Scenario Before After
Update flag without comment "The operation failed due to unmet preconditions" "Comments are required to update in this environment"
Delete segment in use (same generic message) "Segment cannot be deleted because it is used in the feature flag"
Archive prerequisite flag (same generic message) "You cannot archive a flag that is registered as a precondition flag."

Points

  • WithMessageKey() is a chainable method on *BktError — no new constructor functions needed
  • 19 FailedPrecondition errors across 5 packages now send specific messageKeys
  • 8 new translation entries added to both en/backend.json and ja/backend.json for errors that had no existing frontend translation
  • Errors without WithMessageKey() are unaffected — they fall back to the default ErrorType string

All FailedPrecondition errors were sending the same generic messageKey
("FailedPreconditionError"), causing the frontend to display the same
generic message for every precondition failure. This adds a messageKey
override mechanism to BktError so each error can specify its own
translation key, matching the existing frontend i18n entries.

Refs #1253

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings August 20, 2026 12:36

Copilot 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.

Pull request overview

Adds per-error i18n message-key overrides so the frontend can display specific FailedPrecondition messages.

Changes:

  • Adds chainable BktError.WithMessageKey() with default fallback behavior.
  • Assigns specific keys to 19 API errors.
  • Adds frontend translations and tests gRPC metadata propagation.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
pkg/error/error.go Implements message-key overrides.
pkg/error/error_test.go Tests override and fallback behavior.
pkg/api/api/grpc_status_test.go Tests overridden gRPC metadata.
pkg/feature/api/error.go Assigns feature-specific keys.
pkg/environment/api/error.go Assigns environment-specific keys.
pkg/autoops/api/error.go Assigns AutoOps-specific keys.
pkg/notification/api/error.go Assigns notification-specific key.
pkg/tag/api/error.go Assigns tag-specific key.
ui/dashboard/src/@locales/en/backend.json Adds English translations.
ui/dashboard/src/@locales/ja/backend.json Adds Japanese translations.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copilot 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.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Comment thread pkg/feature/api/error.go Outdated
Comment thread pkg/feature/api/error.go Outdated
t-kikuc and others added 2 commits August 28, 2026 17:21
…ite -> prerequisite)

Address review comments on PR #2780:
- Fix "suceeded" typo in error message, variable name, test, and log message
- Fix "prerequsite" typo in error message and E2E test assertion

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…Features)

Keep typo fix and WithMessageKey for statusInvalidArchive while honoring
main's removal of statusVariationInUseByOtherFeatures.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@t-kikuc
t-kikuc marked this pull request as ready for review August 28, 2026 08:50
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.

2 participants