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

chore: Add nil checks before returning wrapped error #5309

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

lukemassa
Copy link
Contributor

@lukemassa lukemassa commented Feb 8, 2025

what

Add nil checks before returning wrapped errors.

why

Partially in prep for #5269, since if we return fmt.Errorf("... : %w", err) when err is nil, it won't, as errors.Wrap(err, "...") does in this situation, return nil.

Additionally, I find that relying on errors.Wrap(err, "...") to return nil if err is nil a bit hard to read. It can also lead to subtle bugs like #5294 and #5312.

I also put a few errors that were split between lines onto one line, which is more specifically in prep for #5269 (which I am writing a script to do replacements for mechanically).

tests

Just running unit tests.

references

Cleaning up code to make #5269 a bit simpler (though I think this change is worth doing on its own).

Signed-off-by: Luke Massa <[email protected]>
Signed-off-by: Luke Massa <[email protected]>
@lukemassa lukemassa requested review from a team as code owners February 8, 2025 18:10
@lukemassa lukemassa requested review from GenPage, nitrocode and X-Guardian and removed request for a team February 8, 2025 18:10
@dosubot dosubot bot added go Pull requests that update Go code refactoring Code refactoring that doesn't add additional functionality labels Feb 8, 2025
@lukemassa lukemassa marked this pull request as draft February 8, 2025 18:18
Signed-off-by: Luke Massa <[email protected]>
@lukemassa lukemassa force-pushed the prep_pkg_error_replacement branch from d56721a to 37f5aa1 Compare February 8, 2025 18:19
Signed-off-by: Luke Massa <[email protected]>
@lukemassa lukemassa marked this pull request as ready for review February 8, 2025 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
go Pull requests that update Go code provider/azuredevops provider/gitlab refactoring Code refactoring that doesn't add additional functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant