-
Notifications
You must be signed in to change notification settings - Fork 435
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
contrib/olivere/elastic: fix ineffectual assignment #1010
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mrkm4ntr maybe I haven't had enough coffee yet, but I don't understand why the previous assignment would have been "ineffectual"? See https://play.golang.org/p/hUfSbzBrIoG
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actual ineffectual assignment is here.
dd-trace-go/contrib/olivere/elastic/elastictrace.go
Line 143 in f86a82b
The scope of
err
is in this block. So I changed the name oferr
in this scope toerr2
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. Subtle. LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see how this changes the logic. Whether the variable is named
err
orerr2
, it is block-scoped and never used outside the block. Likewise, we're not using the outererr
inside the block, so shadowing is not an issue.If there is a bug here, please add a test that exposes the bug which is fixed by this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, the problematic part is here.
dd-trace-go/contrib/olivere/elastic/elastictrace.go
Lines 143 to 145 in f86a82b
if
ioutil.ReadAll(gzr)
returns error, that error is assigned to scopederr
noterr
that function returns. So this function cannot return error ofioutil.ReadAll(gzr)
.The test is still required...? I think it is preferred to introduce linters to detect these kind of bugs automatically.
https://github.com/gordonklaus/ineffassign
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mrkm4ntr Thank you for the clarification. I did not look closely enough my first time through.
A test case is always welcome, but I think we can merge this as-is.