Skip to content

refactor: surface errors for malformed conf struct tag directives#53

Closed
asadijabar wants to merge 1 commit intomainfrom
refactor/fix-silent-tag-misconfiguration
Closed

refactor: surface errors for malformed conf struct tag directives#53
asadijabar wants to merge 1 commit intomainfrom
refactor/fix-silent-tag-misconfiguration

Conversation

@asadijabar
Copy link
Collaborator

@asadijabar asadijabar commented Mar 19, 2026

Summary

  • Malformed conf struct tag directives (e.g., conf:"min:abc", conf:"required:yes", conf:"envv:VAR") were previously silently ignored, causing constraints to be bypassed without any feedback to the developer
  • Introduces ErrCodeInvalidTag and surfaces these as FieldError values during validation
  • Adds parseErrors field to tagConfig to accumulate tag-level errors from parseTag and propagate them through validateFieldWithPresence

Changes

  • errors.go: Add ErrCodeInvalidTag = "invalid_tag" error code
  • binding.go: Add parseErrors to tagConfig; report invalid required/secret values and unknown directives
  • validate.go: Surface parseErrors during validation; return invalid_tag errors for unparseable min/max in all four validateXxxMinMax functions
  • binding_test.go: Update existing tests to expect parseErrors; add parseErrors assertion to test loop
  • validate_test.go: Add TestValidateField_InvalidMinMax (8 cases) and TestValidateField_ParseErrors

Test plan

  • go test -race ./... — all pass
  • make vet / make fmt — clean
  • New tests cover all three categories: unparseable min/max, invalid required/secret values, unknown directives

Copilot AI review requested due to automatic review settings March 19, 2026 17:56
@asadijabar asadijabar self-assigned this Mar 19, 2026
@asadijabar asadijabar force-pushed the refactor/fix-silent-tag-misconfiguration branch from 7ebf6d9 to 39d0ca8 Compare March 19, 2026 17:57
Copy link

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 improves developer feedback by surfacing malformed conf struct tag directives as validation errors (instead of silently ignoring them), introducing a new invalid_tag error code and propagating tag parse errors into field validation.

Changes:

  • Added ErrCodeInvalidTag ("invalid_tag") for malformed/unrecognized tag directives.
  • Extended tag parsing to collect parseErrors for invalid required/secret values and unknown directives, and surfaced them during validation.
  • Updated/added tests to assert parseErrors behavior and invalid_tag errors for unparseable min/max constraints.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
errors.go Introduces the invalid_tag error code for malformed tag directives.
binding.go Adds parseErrors to tagConfig and records unknown/invalid directives during tag parsing (with cache-safe cloning).
validate.go Emits invalid_tag errors for tag parse errors and for unparseable min/max constraints in type-specific validators.
binding_test.go Updates expectations to include parseErrors and asserts them in the test loop.
validate_test.go Adds coverage for invalid min/max parsing and for surfacing parseErrors as validation errors.

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

Comment on lines +23 to +30
// Surface tag parse errors (malformed directives, unknown directives, etc.)
for _, msg := range tags.parseErrors {
errors = append(errors, FieldError{
FieldPath: fieldPath,
Code: ErrCodeInvalidTag,
Message: msg,
})
}
asadijabar added a commit that referenced this pull request Mar 19, 2026
Move min/max tag parseability checks before required/zero-value early
returns in validateFieldWithPresence, so malformed constraints are
always surfaced. The validateXxxMinMax functions now only do value
comparison (parse errors are caught upfront by validateMinMaxParseable).

Addresses code review feedback from PR #53.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
asadijabar added a commit that referenced this pull request Mar 19, 2026
Move min/max tag parseability checks before required/zero-value early
returns in validateFieldWithPresence, so malformed constraints are
always surfaced. The validateXxxMinMax functions now only do value
comparison (parse errors are caught upfront by validateMinMaxParseable).

Addresses code review feedback from PR #53.
@asadijabar asadijabar force-pushed the refactor/fix-silent-tag-misconfiguration branch from eac2a9f to 67992f3 Compare March 19, 2026 18:04
Previously, malformed tag directives were silently ignored:
- `conf:"min:abc"` on an int field silently skipped the min constraint
- `conf:"required:yes"` silently defaulted to true
- `conf:"envv:VAR"` (typo) was silently dropped

This change introduces ErrCodeInvalidTag and surfaces these as
FieldError values during validation, so developers get clear feedback
about misconfigured struct tags instead of silent constraint bypass.

Malformed min/max constraints are checked upfront (before early returns)
so they are reported even when value validation is skipped.
@asadijabar asadijabar force-pushed the refactor/fix-silent-tag-misconfiguration branch from 67992f3 to afd5866 Compare March 19, 2026 18:06
@asadijabar asadijabar closed this Mar 19, 2026
@asadijabar asadijabar deleted the refactor/fix-silent-tag-misconfiguration branch March 19, 2026 18:07
@asadijabar asadijabar restored the refactor/fix-silent-tag-misconfiguration branch March 19, 2026 18:07
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.

2 participants