Skip to content

[Repo Assist] refactor(config): extract detailForKeyword to eliminate duplicate guidance strings#6796

Merged
lpcox merged 1 commit into
mainfrom
repo-assist/fix-issue-6782-extract-detail-for-keyword-f92f26bdb3ad17df
May 31, 2026
Merged

[Repo Assist] refactor(config): extract detailForKeyword to eliminate duplicate guidance strings#6796
lpcox merged 1 commit into
mainfrom
repo-assist/fix-issue-6782-extract-detail-for-keyword-f92f26bdb3ad17df

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

🤖 This is a draft PR from Repo Assist, an automated AI assistant.

Summary

Addresses the duplicate code pattern reported in #6782.

formatErrorContext in internal/config/validation_schema.go previously duplicated 7 identical addDetail() call pairs across two separate paths:

  1. A switch on the terminal keyword from the schema location path (primary path)
  2. A series of strings.Contains message-content fallback checks

The added deduplication 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

  • Extract detailForKeyword(keyword string) (string, []string) as the single source of truth for the 7 keyword→guidance text mappings
  • Add an addFromKeyword inline closure that calls through to detailForKeyword + addDetail
  • The switch body shrinks from 26 lines to 6
  • The fallback if blocks retain their message-matching conditions but no longer contain any literal guidance strings — they all delegate to addFromKeyword
  • Behaviour is identical

Root 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

  • Adds one small exported-private function (~40 lines). Net change is essentially zero lines.
  • detailForKeyword is not exported, so it doesn't add API surface.

Closes #6782

Test Status

⚠️ Infrastructure limitation: The Go module proxy (proxy.golang.org) is blocked by the firewall in this CI environment, preventing go build and go test from 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)
  • Code compiles syntactically (gofmt parses and reformats without errors)
  • All 7 error categories are still handled identically — only the indirection layer changes
  • The existing tests in validation_schema_error_format_test.go cover both the keyword-location path and the message-fallback path and should still pass

Warning

Firewall blocked 2 domains

The following domains were blocked by the firewall during workflow execution:

  • proxy.golang.org
  • releaseassets.githubusercontent.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "proxy.golang.org"
    - "releaseassets.githubusercontent.com"

See Network Configuration for more information.

Generated by Repo Assist · sonnet46 4.6M ·

Add this agentic workflows to your repo

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@851905c06e905bf362a9f6cc54f912e3df747d55

…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>
@lpcox lpcox marked this pull request as ready for review May 31, 2026 13:16
Copilot AI review requested due to automatic review settings May 31, 2026 13:16
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 detailForKeyword as the single source of truth for validation guidance strings.
  • Updates formatErrorContext to reuse the helper for both keyword and message fallback paths.
  • Preserves existing classification behavior while simplifying duplicated addDetail calls.
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

@lpcox lpcox merged commit f954031 into main May 31, 2026
23 checks passed
@lpcox lpcox deleted the repo-assist/fix-issue-6782-extract-detail-for-keyword-f92f26bdb3ad17df branch May 31, 2026 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[duplicate-code] Duplicate Code Pattern: Duplicated addDetail() calls in formatErrorContext

2 participants