Skip to content

Remove extraneous top-level struct args to IsAnyNilOrZero#8651

Merged
jsha merged 1 commit intomainfrom
caa-nil-req
Feb 27, 2026
Merged

Remove extraneous top-level struct args to IsAnyNilOrZero#8651
jsha merged 1 commit intomainfrom
caa-nil-req

Conversation

@aarongable
Copy link
Contributor

@aarongable aarongable commented Feb 26, 2026

We frequently call core.IsAnyNilOrZero(obj, obj.field), to check both that the object (usually a gRPC request) is not nil, and that the required field on the object is not nil. This is pointless for two reasons:

  1. gRPC guarantees that the request object will never be nil, so checking the top-level object is wasted effort.
  2. If the object were nil, then attempting to pass obj.field as the second argument to IsAnyNilOrZero will result in a nil pointer dereference panic before that function even gets to evaluate its first argument. This can be seen here: https://go.dev/play/p/duQK2ZbnxqK

Remove these extraneous first arguments, and operate under the assumption that the request object itself is never nil.

@aarongable aarongable marked this pull request as ready for review February 26, 2026 23:54
@aarongable aarongable requested a review from a team as a code owner February 26, 2026 23:54
@aarongable aarongable requested a review from jsha February 26, 2026 23:54
@beautifulentropy beautifulentropy self-requested a review February 27, 2026 19:47
@jsha jsha merged commit 4fe0a5a into main Feb 27, 2026
28 checks passed
@jsha jsha deleted the caa-nil-req branch February 27, 2026 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants