Fix staticcheck SA5011 nil pointer dereference in retriever test #2050
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.
This PR fixes the staticcheck linter errors that were blocking CI:
What was the problem?
The test had two separate if statements checking for nil conditions:
testGroupNameis emptygroupis nilBoth checks call
t.Skip()to exit the test early. However, the staticcheck linter couldn't understand thatt.Skip()terminates execution, so it thought the code could continue and potentially dereference a nilgrouppointer later in the test.How did we fix it?
We combined both checks into a single if statement using the OR operator (
||). This makes it crystal clear to the linter that ifgroupis nil, the test will skip before any code tries to accessgroup.Servers.The test behavior is exactly the same - it still skips when there are no groups or when the group is nil. We just made the logic clearer for the static analyzer.
Verification