-
Notifications
You must be signed in to change notification settings - Fork 34
Open
Labels
enhancementNew feature or requestNew feature or request
Description
I found several cases in my codebase (kopia/kopia#747) that follow the following buggy pattern:
err := doSomething()
if err != nil {
return result, errors.Wrap(err, "something failed")
}
if somethingElse {
return result, errors.Wrap(err, "something else failed")
}The second errors.Wrap() is incorrect, because it's not wrapping any error (but it's easy to copy/paste it as such).
This is quite hard to spot in code reviews because lines that return errors will always have errors.Wrap() and it looks ok at first glance, until you notice that in this case is err is always nil. Because errors.Wrap(nil, "something") always returns nil this one returns success, which is unintended.
Based on flow analysis, it should be possible to determine that err == nil in this case, and it would be really amazing if the linter could flag this pattern is as misuse.
hsblhsn, dackroyd, MaxBreida, luiscleto and kepelletier
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request