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

internal: fix always-true interface comparison #135

Merged
merged 1 commit into from
Dec 15, 2023

Conversation

sbinet
Copy link
Contributor

@sbinet sbinet commented Dec 15, 2023

This CL corrects the following bug uncovered by staticcheck:

  internal/elements.go:148:6: this comparison is always true (SA4023)
    internal/elements.go:146:18: the lhs of the comparison gets its value from here and has a concrete type

@emersion
Copy link
Owner

Ouch. That's the usual "nil pointer but not actually nil interface" footgun right?

Can we ensure that we never return a nil *Error (which ends up being a non-nil error)? Even if resp.ResponseDescription == ""?

Probably this would help:

var err error
if resp.Error != nil {
    err = resp.Error
}

This CL corrects the following bug uncovered by staticcheck:

```
  internal/elements.go:148:6: this comparison is always true (SA4023)
    internal/elements.go:146:18: the lhs of the comparison gets its value from here and has a concrete type
```

Signed-off-by: Sebastien Binet <binet@cern.ch>
@sbinet
Copy link
Contributor Author

sbinet commented Dec 15, 2023

That's the usual "nil pointer but not actually nil interface" footgun right?

yep, that's the one.

PTAL.

Copy link
Owner

@emersion emersion left a comment

Choose a reason for hiding this comment

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

Thank you!

@emersion emersion enabled auto-merge (rebase) December 15, 2023 14:07
@emersion emersion merged commit 7d337ac into emersion:master Dec 15, 2023
1 check passed
@sbinet sbinet deleted the staticcheck-iface-cmp branch December 15, 2023 14:08
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

2 participants