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

jobs: fix improperly wrapped errors #72351

Merged
merged 1 commit into from
Nov 3, 2021

Conversation

rafiss
Copy link
Collaborator

@rafiss rafiss commented Nov 2, 2021

refs #42510

I'm working on a linter that detects errors that are not wrapped
correctly, and it discovered these.

Release note: None

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@rafiss rafiss requested a review from adityamaru November 2, 2021 20:52
I'm working on a linter that detects errors that are not wrapped
correctly, and it discovered these.

Release note: None
@rafiss rafiss requested review from a team November 3, 2021 02:12
Copy link
Contributor

@ajwerner ajwerner left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 5 of 5 files at r1, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @adityamaru)

@rafiss
Copy link
Collaborator Author

rafiss commented Nov 3, 2021

tftr!

bors r=ajwerner

@craig
Copy link
Contributor

craig bot commented Nov 3, 2021

Build succeeded:

@craig craig bot merged commit 05d3662 into cockroachdb:master Nov 3, 2021
@adityamaru
Copy link
Contributor

@rafiss just a headsup that this seems to have caused #72371 failures. The reason is that https://github.com/cockroachdb/cockroach/pull/72351/files#diff-6b2c8ccac0d3ee5f528d6661fcc9b37a032f7ac928cbfaebc72a05db34e47b4dR179 will now return nil if the err it is wrapping is nil. We do in fact want to return an error if we find a record, even if getRecord itself didn't return an error, because we are waiting for the record to get reconciled.

I'll send out a fix for this, but might be something to keep in mind when running the new linter! I (along with @miretskiy and @stevendanna) also feel that wrapping a nil error should be disallowed. While it saves a few lines of code it doesn't seem like a very desirable side effect? This might be a discussion for another issue.

@rafiss
Copy link
Collaborator Author

rafiss commented Nov 3, 2021

thanks for explaining @adityamaru !

I can add a thing to my linter to try to detect nil wrapped errors.

to be fully robust to the problem, a nil-check could be added to the Wrap function itself. maybe @knz has thoughts on that. (it would be backwards incompatible, but perhaps a good idea)

@knz
Copy link
Contributor

knz commented Nov 3, 2021

a nil-check could be added to the Wrap function itself.

huh, no - it's a feature:

result, err := somefunc()
return result, errors.Wrap(err, ...)

@stevendanna
Copy link
Collaborator

I can add a thing to my linter to try to detect nil wrapped errors.

Nice. The nillness linter catches the "definitely nil" cases, but doesn't catch the "maybe nil" cases.

@stevendanna
Copy link
Collaborator

stevendanna commented Nov 3, 2021

huh, no - it's a feature:

I think that the argument is that while it is a feature, the cost isn't worth the benefit. That said, changing it would put us out-of-line with other similar functions in the Go ecosystem.

@knz
Copy link
Contributor

knz commented Nov 3, 2021

That said, changing it would put us out-of-line with other similar functions in the Go ecosystem.

:that:

@rafiss rafiss deleted the fix-jobs-errwrap branch November 3, 2021 21:51
craig bot pushed a commit that referenced this pull request Dec 15, 2021
71877: lint: add new errwrap linter r=ajwerner,knz a=rafiss

fixes #42510

This linter checks if we don't correctly wrap errors.

The `/* nolint:errwrap */` comment can be used to disable the linter inline.

See individual commits for mistakes this linter caught.
It had already caught a few in #72353, #72352, #72351, #72350, and #72349.

Release note: None

Co-authored-by: Rafi Shamim <[email protected]>
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.

6 participants