-
Notifications
You must be signed in to change notification settings - Fork 78
Open
Description
The linter incorrectly flags a return nil, err statement where err is generated by google.golang.org/grpc/status.Error.
The linter seems to assume that status.Error() can return a nil error, which is only true if the gRPC code is codes.OK. When a non-OK code like codes.InvalidArgument is used, the function is guaranteed to return a non-nil error. The linter's static analysis doesn't appear to differentiate between these cases, leading to a false positive.
package main
import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
// This function will be flagged by the nilerr linter.
func someFunction(isValid bool) (*string, error) {
if !isValid {
// The linter complains on the following line, even though
// codes.InvalidArgument guarantees a non-nil error.
return nil, status.Error(codes.InvalidArgument, "input is invalid")
}
result := "success"
return &result, nil
}
The output will be:
literal `nil` returned from `someFunction()` in position 0 when the error return in position 1 is not guaranteed to be non-nil through all paths
Expected Behavior:
The linter should not report an error for this code, as status.Error(codes.InvalidArgument, "...") is guaranteed to produce a non-nil error, making a (nil, nil) return impossible.
Metadata
Metadata
Assignees
Labels
No labels