Go

Go

Made by DeepSource

Poorly formed nilness guards GO-E1008

Bug risk
Critical

Poorly formed nilness guards can be fatal as they might lead to unwanted panic because of nil pointer dereferences. Depending on the binary expression, the logic might not work as expected because of the poorly formed guards. In a binary expression, it is crucial to creating good nilness guards so that executing the other operand in the expression is safe.

Bad practice

if cmd == nil && cmd.Execute() == 0 {
    // do something
}

if cmd != nil || cmd.Execute() == 0 {
    // do something
}

Recommended

if cmd != nil && cmd.Execute() == 0 {
    // do something
}

if cmd == nil || cmd.Execute() == 0 {
    // do something
}