[Repo Assist] refactor(config): extract detailForKeyword to eliminate duplicate guidance strings#6796
Merged
lpcox merged 1 commit intoMay 31, 2026
Conversation
…dance strings The formatErrorContext function previously duplicated identical addDetail() calls across two separate paths: a keyword-location switch and a series of message-content fallback checks. This meant that updating a guidance string for any of the 7 error categories required touching two places in sync. Extract a detailForKeyword(keyword string) (string, []string) helper that centralises the keyword→guidance mapping. Both the switch path and the fallback path now call addFromKeyword (a thin wrapper around detailForKeyword + addDetail) instead of repeating the strings. Changes: - New detailForKeyword function (~40 lines) as single source of truth - formatErrorContext switch reduced from 26 lines to 6 lines - Fallback if-blocks simplified: no more literal strings, just addFromKeyword calls - Behaviour is identical; the added deduplication map prevents double output Closes #6782 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors JSON schema validation error formatting to centralize keyword-specific guidance text, reducing duplication between schema-location classification and message-based fallback handling.
Changes:
- Adds
detailForKeywordas the single source of truth for validation guidance strings. - Updates
formatErrorContextto reuse the helper for both keyword and message fallback paths. - Preserves existing classification behavior while simplifying duplicated
addDetailcalls.
Show a summary per file
| File | Description |
|---|---|
internal/config/validation_schema.go |
Centralizes validation error detail strings and delegates both primary and fallback paths through the shared helper. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 1/1 changed files
- Comments generated: 0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 This is a draft PR from Repo Assist, an automated AI assistant.
Summary
Addresses the duplicate code pattern reported in #6782.
formatErrorContextininternal/config/validation_schema.gopreviously duplicated 7 identicaladdDetail()call pairs across two separate paths:switchon the terminal keyword from the schema location path (primary path)strings.Containsmessage-content fallback checksThe
addeddeduplication map prevented double-output at runtime, but updating any guidance string required touching both blocks in sync. Missing one would produce inconsistent messages between the primary and fallback paths.Fix
detailForKeyword(keyword string) (string, []string)as the single source of truth for the 7 keyword→guidance text mappingsaddFromKeywordinline closure that calls through todetailForKeyword+addDetailswitchbody shrinks from 26 lines to 6ifblocks retain their message-matching conditions but no longer contain any literal guidance strings — they all delegate toaddFromKeywordRoot Cause
The two-path design (keyword-location switch + message-fallback) is intentional and useful. But the guidance text was copy-pasted rather than shared, creating a maintenance hazard.
Trade-offs
detailForKeywordis not exported, so it doesn't add API surface.Closes #6782
Test Status
proxy.golang.org) is blocked by the firewall in this CI environment, preventinggo buildandgo testfrom running. This is a known limitation affecting all recent Repo Assist PRs in this repo.Manual verification:
gofmt -d internal/config/validation_schema.go→ no diff (no formatting issues)validation_schema_error_format_test.gocover both the keyword-location path and the message-fallback path and should still passWarning
Firewall blocked 2 domains
The following domains were blocked by the firewall during workflow execution:
proxy.golang.orgreleaseassets.githubusercontent.comSee Network Configuration for more information.
Add this agentic workflows to your repo
To install this agentic workflow, run