Skip to content

Expose errors returned by validateFn#1579

Open
puneetdixit200 wants to merge 1 commit into
go-playground:masterfrom
puneetdixit200:fix-validatefn-error-propagation
Open

Expose errors returned by validateFn#1579
puneetdixit200 wants to merge 1 commit into
go-playground:masterfrom
puneetdixit200:fix-validatefn-error-propagation

Conversation

@puneetdixit200
Copy link
Copy Markdown

Fixes Or Enhances

Fixes #1575.

validateFn methods that return a non-nil error now keep that error attached to the generated field validation error. Callers can inspect it with errors.Is or errors.As through either the returned ValidationErrors value or the individual FieldError.

This keeps the existing FieldError interface and validation failure shape unchanged while making the underlying Validate() error result accessible.

Make sure that you've checked the boxes below before you submit PR:

  • Tests exist or have been written that cover this particular change.

Verification

  • GOMODCACHE=/tmp/validator-gomodcache GOCACHE=/tmp/validator-gocache go test ./... -run TestValidateFn -count=1
  • GOMODCACHE=/tmp/validator-gomodcache GOCACHE=/tmp/validator-gocache go test -cover -race ./...
  • PATH=/tmp/validator-bin:$PATH GOMODCACHE=/tmp/validator-gomodcache GOCACHE=/tmp/validator-gocache golangci-lint run
  • git diff --check

@go-playground/validator-maintainers

@puneetdixit200 puneetdixit200 requested a review from a team as a code owner May 22, 2026 05:54
Copy link
Copy Markdown
Member

@zemzale zemzale left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems good.

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.

[Bug]: validateFn does not propagage errors upwards

2 participants