Refactor TimeoutPositive to reuse TimeoutMinimum and remove duplicated validator logic#7105
Merged
Merged
Conversation
5 tasks
Copilot
AI
changed the title
[WIP] Refactor overlapping validators TimeoutPositive and PositiveInteger
Refactor Jun 6, 2026
TimeoutPositive to reuse TimeoutMinimum and remove duplicated validator logic
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the configuration validation rules to reduce duplicated timeout validation logic by making TimeoutPositive delegate to the shared TimeoutMinimum validator, while keeping the TimeoutPositive API unchanged.
Changes:
- Replaced
TimeoutPositive’s inline>= 1validation withTimeoutMinimum(timeout, 1, ...). - Updated
TimeoutPositivedoc comments to describe its wrapper/delegation behavior.
Show a summary per file
| File | Description |
|---|---|
| internal/config/rules/rules.go | Refactors TimeoutPositive to reuse TimeoutMinimum and updates associated doc comments. |
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: 1
Comment on lines
+107
to
+112
| // TimeoutPositive validates that a timeout value is at least 1. | ||
| // Returns nil if valid, *ValidationError if invalid. | ||
| // It is a convenience wrapper around TimeoutMinimum with min=1. | ||
| // Error message and suggestion formatting are provided by TimeoutMinimum. | ||
| func TimeoutPositive(timeout int, fieldName, jsonPath string) *ValidationError { | ||
| log.Printf("Validating timeout: field=%s, value=%d, jsonPath=%s", fieldName, timeout, jsonPath) | ||
| if timeout < 1 { | ||
| log.Printf("Timeout validation failed: %s=%d is not positive", fieldName, timeout) | ||
| return &ValidationError{ | ||
| Field: fieldName, | ||
| Message: fmt.Sprintf("%s must be at least 1, got %d", fieldName, timeout), | ||
| JSONPath: jsonPath, | ||
| Suggestion: "Use a positive number of seconds (e.g., 30)", | ||
| } | ||
| } | ||
| return nil | ||
| return TimeoutMinimum(timeout, 1, fieldName, jsonPath) |
Collaborator
|
@copilot address review feedback |
…r of seconds (e.g., 30)"
Contributor
Author
Fixed in the latest commit. |
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.
internal/config/rules/rules.gohad overlapping>= 1validation logic acrossTimeoutPositiveandPositiveInteger, withTimeoutPositiveeffectively duplicating functionality already represented byTimeoutMinimum(..., 1, ...). This change consolidates the timeout path onto the shared minimum validator while keeping the existing API surface intact.Validator deduplication
TimeoutPositive’s inline validation/error construction with delegation toTimeoutMinimum(timeout, 1, fieldName, jsonPath).API and call-site stability
TimeoutPositivefunction signature and usage unchanged.Documentation alignment
TimeoutPositivedoc comments to explicitly describe wrapper behavior and delegated error/suggestion formatting.