From ef511964f7e2f58adcf0456ab35d8fb2f6c053e6 Mon Sep 17 00:00:00 2001 From: Anton Soroko Date: Mon, 17 Feb 2025 22:37:52 +0300 Subject: [PATCH] Use correct pointer in errors.As(). Only *InvalidValidationError implements error, so must use double pointer. --- _examples/simple/main.go | 3 ++- _examples/struct-level/main.go | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/_examples/simple/main.go b/_examples/simple/main.go index 5a5da4dd..606822b1 100644 --- a/_examples/simple/main.go +++ b/_examples/simple/main.go @@ -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 } diff --git a/_examples/struct-level/main.go b/_examples/struct-level/main.go index 1885fc70..faba03fb 100644 --- a/_examples/struct-level/main.go +++ b/_examples/struct-level/main.go @@ -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 }