Skip to content

Refactor schema validation error construction to remove duplicated invariant arguments#8955

Merged
lpcox merged 2 commits into
mainfrom
copilot/duplicate-code-fix-schema-validation-error
Jul 8, 2026
Merged

Refactor schema validation error construction to remove duplicated invariant arguments#8955
lpcox merged 2 commits into
mainfrom
copilot/duplicate-code-fix-schema-validation-error

Conversation

Copilot AI commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

internal/config/validation_server.go repeated the same SchemaValidationError(server.Type, ..., jsonPath, ...) pattern across custom-schema fetch/compile/validate paths. This change reduces that duplication by locally capturing invariant arguments while keeping all error messages and control flow intact.

  • What changed

    • Added a local schemaErr(message, hint) closure in:
      • validateAgainstCustomSchema
      • validateServerAgainstSchema
    • Replaced repeated SchemaValidationError(server.Type, ..., jsonPath, ...) calls with schemaErr(...).
  • Behavioral impact

    • No functional changes intended: same error conditions, same messages/hints, same returned error type/context.
    • Reduces boilerplate and lowers risk of future copy/paste inconsistency for server.Type / jsonPath.
  • Example (pattern before/after)

    // before
    return SchemaValidationError(server.Type, msg, jsonPath, hint)
    
    // after
    schemaErr := func(message, hint string) error {
        return SchemaValidationError(server.Type, message, jsonPath, hint)
    }
    return schemaErr(msg, hint)

Copilot AI changed the title [WIP] Refactor repeated SchemaValidationError calls in validation server Refactor schema validation error construction to remove duplicated invariant arguments Jul 8, 2026
Copilot AI requested a review from lpcox July 8, 2026 17:14
Copilot finished work on behalf of lpcox July 8, 2026 17:14
@lpcox lpcox marked this pull request as ready for review July 8, 2026 17:17
Copilot AI review requested due to automatic review settings July 8, 2026 17:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 custom-schema validation in internal/config/validation_server.go to reduce repeated SchemaValidationError(server.Type, ..., jsonPath, ...) construction by introducing a small local helper closure (schemaErr) in the two functions that emit these errors, while keeping the same messages/hints and control flow.

Changes:

  • Added a local schemaErr(message, hint) helper in validateAgainstCustomSchema.
  • Added a local schemaErr(message, hint) helper in validateServerAgainstSchema.
  • Replaced repeated SchemaValidationError(server.Type, ..., jsonPath, ...) call sites with schemaErr(...).
Show a summary per file
File Description
internal/config/validation_server.go Reduces boilerplate in custom-schema fetch/compile/validate error returns by capturing invariant args (server.Type, jsonPath) in a local helper.

Review details

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 1/1 changed files
  • Comments generated: 0
  • Review effort level: Low

@lpcox lpcox merged commit 41137bf into main Jul 8, 2026
37 checks passed
@lpcox lpcox deleted the copilot/duplicate-code-fix-schema-validation-error branch July 8, 2026 17:21
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.

[duplicate-code] Duplicate Code Pattern: Repeated SchemaValidationError Calls with Invariant Arguments

3 participants