Replace raw fmt.Errorf with RequiredStringField and NonEmptyString validators#8356
Merged
Conversation
…lidators
Add RequiredStringField helper to validation_rules.go that returns
*ValidationError with structured context (Field, JSONPath, Suggestion)
instead of plain error strings.
Replace raw 'if field == "" { return fmt.Errorf(...) }' patterns with
calls to RequiredStringField and NonEmptyString across:
- guard_policy.go: min-integrity check in UnmarshalJSON
- guard_policy_parse.go: min-integrity check in BuildAllowOnlyPolicy
- guard_policy_validation.go: write-sink.accept, repos scope,
string slice, and tool-call-limits empty entry checks
- validation.go: tool response filter empty name/value checks
Update all affected test assertions to match the new structured
error message format from ValidationError.
Fixes #8321
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves config validation consistency by introducing a RequiredStringField helper that returns structured *ValidationError instances (with Field, JSONPath, Suggestion) and by replacing several ad-hoc fmt.Errorf empty-string checks with RequiredStringField / NonEmptyString across the config and guard-policy validation paths.
Changes:
- Added
RequiredStringField(...) *ValidationErrorto centralize “required string” checks with structured context. - Migrated several guard policy and tool-response-filter validations from raw
fmt.ErrorftoRequiredStringField/NonEmptyString. - Updated unit/coverage tests to assert against the new structured error formatting and messages.
Show a summary per file
| File | Description |
|---|---|
| internal/config/validation.go | Converts tool response filter empty-name/value checks to NonEmptyString-based structured validation. |
| internal/config/validation_test.go | Updates expected substrings to match new ValidationError.Error() output for tool response filter validation. |
| internal/config/validation_rules.go | Adds the new RequiredStringField validator helper returning *ValidationError. |
| internal/config/validation_rules_test.go | Adds unit tests for RequiredStringField. |
| internal/config/validate_helpers_coverage_test.go | Updates coverage test expectations for the new structured validation messages. |
| internal/config/guard_policy.go | Uses RequiredStringField for AllowOnlyPolicy min-integrity required validation. |
| internal/config/guard_policy_validation.go | Replaces several empty-string checks with NonEmptyString for structured errors. |
| internal/config/guard_policy_unmarshal_coverage_test.go | Updates expected error substrings for missing min-integrity and empty entries. |
| internal/config/guard_policy_test.go | Updates expected error substrings for empty-entry cases to match NonEmptyString. |
| internal/config/guard_policy_parse.go | Uses RequiredStringField for min-integrity required validation in policy builder. |
| internal/config/guard_policy_coverage_test.go | Updates expected substrings in guard policy validation coverage tests. |
| internal/config/config_core_test.go | Updates expected substrings for tool response filter validation errors in TOML load tests. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 12/12 changed files
- Comments generated: 1
- Review effort level: Low
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This was referenced Jun 30, 2026
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.
Summary
Fixes #8321
Adds a
RequiredStringFieldhelper tovalidation_rules.gothat returns*ValidationErrorwith structured context (Field, JSONPath, Suggestion) instead of plainfmt.Errorferror strings. Replaces rawif field == "" { return fmt.Errorf(...) }patterns with calls toRequiredStringFieldand the existingNonEmptyStringvalidator across the config package.Changes
New function:
RequiredStringFieldinternal/config/validation_rules.goRequiredStringField(value, fieldName, jsonPath, suggestion string) *ValidationErrornilif value is non-empty, structured*ValidationErrorif emptyCall sites converted
guard_policy.go— min-integrity check inAllowOnlyPolicy.UnmarshalJSONguard_policy_parse.go— min-integrity check inBuildAllowOnlyPolicyguard_policy_validation.go— 4 empty-entry checks:write-sink.acceptentriesallow-only.reposscope entriesnormalizeStringSliceentries (blocked-users, refusal-labels, approval-labels, trusted-users, endorsement-reactions, disapproval-reactions)tool-call-limitskeysvalidation.go— tool response filter empty name/value checksTests updated
All affected test assertions updated to match the new structured error message format from
ValidationError.Error(). All existing tests pass.Verification
make agent-finishedpasses (format, build, lint, all tests including Rust guard).