If a return statement returns a value that evaluates to
nil, it is better to return
An off-by-one error happens due to incorrectly handled edge-cases.
The cancellation function returned by
WithDeadline must be called or the new context will remain live until its parent context is cancelled. (The background context is never cancelled.) This is usually an issue either because the variable was assigned to the blank identifier, or because there exists a control-flow path from the call to a return statement and that path does not "use" the cancel function.
Some conditions become unsafe when not exhaustive. For example, in the following example, the array
xs may be of zero length, but not necessarily
nil (say, when
xs := make(someType, 0)). Hence, the second part of the condition will panic if there are no elements yet.