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

Propagate/wrap invalid account errors #3313

Merged
merged 2 commits into from
Apr 7, 2021

Conversation

ashleyvega
Copy link
Contributor

This PR slightly improves error handling by propagating the ID of invalid account.

It also uses errors.Wrap(err, "info") to show where some errors came from.

Copy link
Member

@jeremyletang jeremyletang left a comment

Choose a reason for hiding this comment

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

Can we avoid using errors.Wrap, and use fmt.Errorf("... %w ...") iunstead?

@ashleyvega
Copy link
Contributor Author

@jeremyletang I think we should switch to wrapping errors in structs instead of in strings.

See https://dave.cheney.net/2016/04/27/dont-just-check-errors-handle-them-gracefully for details.

@jeremyletang
Copy link
Member

@jeremyletang I think we should switch to wrapping errors in structs instead of in strings.

See https://dave.cheney.net/2016/04/27/dont-just-check-errors-handle-them-gracefully for details.

I think we should use the %w flag, which build errors that can be wrapped and unwrapped with std library. https://golang.org/pkg/fmt/#Errorf, and that we can use with errors.As / errors.Is.

@ashleyvega
Copy link
Contributor Author

$ find -name vendor -prune -o -name '*.go' -print | xargs grep errors.Wrap |wc -l
60

$ find -name vendor -prune -o -name '*.go' -print | xargs grep -E 'fmt.Errorf.*?%w' |wc -l
31

$ find -name vendor -prune -o -name '*.go' -print | xargs grep fmt.Errorf |wc -l
462

$ find -name vendor -prune -o -name '*.go' -print | xargs grep 'return.*Err[A-Z]' |wc -l
510

There is already a mixture of error reporting going on in the app atm. Perhaps the debate on the One Correct Way can be postponed for now.

@jeremyletang
Copy link
Member

$ find -name vendor -prune -o -name '*.go' -print | xargs grep errors.Wrap |wc -l
60

$ find -name vendor -prune -o -name '*.go' -print | xargs grep -E 'fmt.Errorf.*?%w' |wc -l
31

$ find -name vendor -prune -o -name '*.go' -print | xargs grep fmt.Errorf |wc -l
462

$ find -name vendor -prune -o -name '*.go' -print | xargs grep 'return.*Err[A-Z]' |wc -l
510

There is already a mixture of error reporting going on in the app atm. Perhaps the debate on the One Correct Way can be postponed for now.

Well ultimately they are all valid ones, just the 2 first ones serves the same purpose. And we'll go with the second one which provides same features from the standard library. So let's just not add more work for the future us at replacing errros.Wrap maybe?

@EVODelavega
Copy link
Contributor

We currently have a mix of error reporting stuff because errors.Wrap was added in version 1.13. Some errors, mainly the client facing ones are declared as variables (hence return Err....). That's perfectly valid/fine. Some errors are constructed on the fly (fmt.Errorf). There's no definitive way to return errors to be discussed. Wrapping errors in a struct is kind of pointless, an error is just any type with the interface Error() string. A struct wouldn't add any more valuable information unless we manually set it. Using %w or other format specifiers are now built-in, so going forwards, we should be using that, rather than our own structs we have to maintain.

@pennyandrews
Copy link
Contributor

pennyandrews commented Apr 7, 2021

Hey @jeremyletang @ashleyvega @EVODelavega, looks like an interesting debate here and one that would be a good candidate to discuss and agree a standard approach as a team. For right now, we need to get this work merged (!) and as it seems there is already a mix of approaches I would suggest going for the one that is already done rather than changing it now, to get it through and then I propose we use the retrospective time tomorrow afternoon to see if there is a standard approach we could all get onboard with going forward. Sound OK?

@jeremyletang jeremyletang merged commit 965a0fe into develop Apr 7, 2021
@jeremyletang jeremyletang deleted the improve-error-distribute-iquidity-fees branch April 7, 2021 13:43
@edd edd mentioned this pull request Apr 7, 2021
@edd edd mentioned this pull request Apr 15, 2021
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.

None yet

4 participants