# panic: proto: Marshal called with nil

- **ID:** `go/proto-nil-message-marshal`
- **Domain:** go
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

proto.Marshal was passed a nil pointer, often from a handler returning (nil, nil) or an uninitialized nested field.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| google.golang.org/protobuf 1.31+ | active | — | — |

## Workarounds

1. **** (95% success)
   ```
   Always return a non-nil message or an explicit status error:
if user == nil {
  return nil, status.Error(codes.NotFound, "user not found")
}
return &pb.GetUserResponse{User: user}, nil
   ```
2. **** (90% success)
   ```
   Add a unit test that asserts every handler returns either a non-nil message or a non-nil error.
   ```

## Dead Ends

- **** — Masks the bug; nil responses keep leaking to clients as empty messages. (85% fail)
- **** — Changes the API contract; clients can no longer distinguish 'no result' from 'empty result'. (70% fail)
