# error: proto: cannot marshal, message is nil

- **ID:** `go/grpc-proto-marshal-error`
- **Domain:** go
- **Category:** data_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Attempting to marshal a nil protobuf message into bytes, which is not allowed in protobuf.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 1.0 | active | — | — |

## Workarounds

1. **Initialize the message before marshaling** (99% success)
   ```
   msg := &MyMessage{}
b, err := proto.Marshal(msg)
   ```
2. **Use proto.MarshalOptions with deterministic output** (98% success)
   ```
   b, err := proto.MarshalOptions{}.Marshal(msg)
   ```

## Dead Ends

- **Use a zero-value message instead of nil** — A zero-value message still marshals to empty bytes, but if the message is nil, it will panic or error. (50% fail)
- **Check for nil but continue with empty bytes** — You need to handle the nil case explicitly, otherwise the error propagates. (40% fail)
