# panic: proto: Marshal called with nil

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

## Root Cause

proto.Marshal was called with a nil message pointer, typically after a function returned (nil, nil) or an uninitialized struct field.

## Version Compatibility

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

## Workarounds

1. **** (92% success)
   ```
   Guard against nil before marshaling:
if msg == nil { return errors.New("nil message") }
b, err := proto.Marshal(msg)
   ```
2. **** (90% success)
   ```
   Fix the producer function to never return (nil, nil):
func build() (*pb.Msg, error) {
  if bad { return nil, errBad }
  return &pb.Msg{...}, nil
}
   ```

## Dead Ends

- **** — Hides the bug; the caller still receives garbage or a swallowed error. (80% fail)
- **** — Masks the real problem (nil constructor) and may send semantically empty data. (70% fail)
