False positive #3
Closed this issue · 2 comments
ruchikaguptaa commented
The linter complains ineffectual assignment to dataclientUsingSecondarykey
on second assignment of dataclientUsingSecondaryKey = true
. But the variable is being used again later on. Looks like bug?
var dataclientUsingSecondaryKey bool
containerExists, rerr := storagedataclient.ContainerExists(ctx, goal.ContainerName)
if rerr != nil {
dataclientUsingSecondaryKey = true
}
logger.TraceInfof("container '%s' exists: %t", goal.ContainerName, containerExists)
if goal.IsDeleting {
if rerr := storagedataclient.DeleteContainer(ctx, goal.ContainerName); rerr != nil {
if !dataclientUsingSecondaryKey {
dataclientUsingSecondaryKey = true
storagedataclient.DeleteContainer(ctx, goal.ContainerName)
}
}
}
logger.TraceInfof("Delete container '%s' succeeded.", goal.ContainerName)
return retry.Success, nil, nil
}
if rerr := storagedataclient.CreateContainer(ctx, goal.ContainerName, azStorage.ContainerAccessTypePrivate); rerr != nil {
if !dataclientUsingSecondaryKey {
logger.TraceInfof("Creating storagedataclient with secondary key since CreateContainer returned AuthenticationFailed")
}
}
gordonklaus commented
The second assignment is followed unconditionally by a return
, so it is indeed ineffectual.
(There is an extra closing brace in the middle of your code, such that it does not quite parse. Please post valid a Go code snippet if you still have an issue.)
ruchikaguptaa commented
@gordonklaus Thanks for pointing that out and sorry for the trouble. I missed that.