ardanlabs / service

Starter-kit for writing services in Go using Kubernetes.

Home Page:https://www.ardanlabs.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Type assertion on errors fails on wrapped error

mrbardia72 opened this issue · comments

https://github.com/ardanlabs/service/blob/master/foundation/validate/validate.go#L47

Convert to the following code:

	var verrors validator.ValidationErrors
		ok := errors.As(err, &verrors)
		if !ok {
			return err
		}
‍‍```

Yea, that is a good point. I guess the current code base doesn't not have this situation. Your PR does not have this change, so I can't accept that. I will make this change.

I looked at this closer. The error will never be wrapped.

if err := validate.Struct(val); err != nil {

    // Use a type assertion to get the real error value.
    verrors, ok := err.(validator.ValidationErrors)
     if !ok {
         return err
     }

Notice the error we are evaulating is coming from the validate.Struct call. This is not an error we are constructing and could be wrapped.