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

Go / Add additional context to error messages #151

Open
raserva opened this issue Feb 9, 2022 · 2 comments
Open

Go / Add additional context to error messages #151

raserva opened this issue Feb 9, 2022 · 2 comments
Labels
cleanup To keep the code clean and readable good first issue Good for newcomers
Milestone

Comments

@raserva
Copy link
Contributor

raserva commented Feb 9, 2022

As a follow-up, let's add a TODO to add context to these errors. It's generally a best practice to wrap all errors with some context:

return nil, fmt.Errorf("failed to do whatever: %w", err)

Originally posted by @sethvargo in #150 (comment)

The above was in reference to the following file: clients/go/pkg/auditopt/config.go however it occurs elsewhere in our go codebase as well.

@yolocs yolocs added the cleanup To keep the code clean and readable label Feb 9, 2022
@yolocs
Copy link
Contributor

yolocs commented Feb 9, 2022

To be clear, the general advice is right but we should not blindly add additional context for every err return. I've seen many cases where the inner err already provides clear error message and the outer message simply repeats it. We should avoid that.

@crwilcox
Copy link
Contributor

Agreed. in general more context is better, but too much of a good thing can be a bad thing.

@yolocs yolocs added this to the Backlog milestone Feb 22, 2022
@yolocs yolocs added the good first issue Good for newcomers label Mar 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleanup To keep the code clean and readable good first issue Good for newcomers
Development

No branches or pull requests

3 participants