Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use correct pointer in errors.As(). Fix "panic: errors: *target must be interface or implement error" in examples. #1378

Merged
merged 1 commit into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion _examples/simple/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ func validateStruct() {
// this check is only needed when your code could produce
// an invalid value for validation such as interface with nil
// value most including myself do not usually have code like this.
if errors.As(err, &validator.InvalidValidationError{}) {
var invalidValidationError *validator.InvalidValidationError
if errors.As(err, &invalidValidationError) {
fmt.Println(err)
return
}
Expand Down
3 changes: 2 additions & 1 deletion _examples/struct-level/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ func main() {
// this check is only needed when your code could produce
// an invalid value for validation such as interface with nil
// value most including myself do not usually have code like this.
if errors.As(err, &validator.InvalidValidationError{}) {
var invalidValidationError *validator.InvalidValidationError
if errors.As(err, &invalidValidationError) {
fmt.Println(err)
return
}
Expand Down
Loading