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

Type assertion on errors fails on wrapped error #336

Closed
mrbardia72 opened this issue Dec 3, 2023 · 2 comments
Closed

Type assertion on errors fails on wrapped error #336

mrbardia72 opened this issue Dec 3, 2023 · 2 comments

Comments

@mrbardia72
Copy link
Contributor

mrbardia72 commented Dec 3, 2023

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
		}
‍‍```

@ardan-bkennedy
Copy link
Contributor

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.

@ardan-bkennedy
Copy link
Contributor

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.

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

No branches or pull requests

2 participants