refactor: extract newValidationError helper to deduplicate log+return pattern in validation functions#8503
Merged
Conversation
Closed
6 tasks
…ication
Add a private newValidationError(logMsg, field, message, jsonPath, suggestion)
helper in validation_errors.go that centralises the repeated
logValidation.Printf + return &ValidationError{...} pattern.
Pattern B (validation_errors.go): UnsupportedType, UndefinedVariable,
MissingRequired, InvalidPattern, SchemaValidationError each had an identical
log+return body; all five now delegate to the helper.
Pattern A (validation_rules.go): PortRange, PositiveInteger, TimeoutMinimum,
TimeoutRange, AbsolutePath kept their per-function entry-log line but their
failure-log + return block now uses the same helper, eliminating the repeated
pair of logValidation.Printf + &ValidationError{} on every failure path.
No validation error messages, field values, or public API changed.
Closes #8477
Copilot
AI
changed the title
[WIP] Refactor duplicated validation functions to reduce code repetition
refactor: extract newValidationError helper to deduplicate log+return pattern in validation functions
Jul 2, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors config validation code by extracting a shared newValidationError helper to centralize the repeated “log + construct *ValidationError” pattern, reducing duplication across validation helpers in internal/config.
Changes:
- Added a private
newValidationError(logMsg, field, message, jsonPath, suggestion)helper to log and construct*ValidationError. - Updated several validation error constructors in
validation_errors.goto delegate to the helper. - Updated several rule validators in
validation_rules.goto replace inline “log +&ValidationError{...}” blocks withnewValidationError(...)calls while preserving entry logs.
Show a summary per file
| File | Description |
|---|---|
| internal/config/validation_errors.go | Introduces newValidationError and migrates multiple error constructors to use it. |
| internal/config/validation_rules.go | Replaces repeated failure “log + return ValidationError” blocks with newValidationError(...) calls in several validators. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Low
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.
14 validation functions across
validation_errors.goandvalidation_rules.goindependently calledlogValidation.Printfthen returned a&ValidationError{...}literal — meaning any log format change required editing every call site.Changes
internal/config/validation_errors.go— new private helper:UnsupportedType,UndefinedVariable,MissingRequired,InvalidPattern,SchemaValidationError): each had an identical log-then-return body; all five now delegate to the helper.internal/config/validation_rules.goPortRange,PositiveInteger,TimeoutMinimum,TimeoutRange,AbsolutePath): per-function entry logs are retained as-is (they vary by parameters), but each failure-log +&ValidationError{}block is replaced with a singlenewValidationError(...)call.No validation error messages, field values, or public API changed.