# rpc error: code = Internal desc = grpc: server failed to encode response: rpc error: code = Internal desc = grpc: error while marshaling: proto: Marshal called with nil

- **ID:** `go/grpc-internal-error-server-panic`
- **Domain:** go
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

The server handler returned a nil response message, and the gRPC framework attempted to marshal it, causing a panic or error.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 1.x | active | — | — |

## Workarounds

1. **** (95% success)
   ```
   func (s *server) YourMethod(ctx context.Context, req *pb.Request) (*pb.Response, error) {
    // Always return a valid response
    return &pb.Response{}, nil
}
   ```
2. **** (90% success)
   ```
   func validateResponseInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
    resp, err := handler(ctx, req)
    if err != nil { return nil, err }
    if resp == nil { return nil, status.Error(codes.Internal, "nil response") }
    return resp, nil
}
   ```

## Dead Ends

- **** — Recovering from the panic without fixing the nil response still results in an error sent to the client. (70% fail)
- **** — Returning an empty message may be semantically incorrect and does not address the root cause. (50% fail)
