{
  "id": "go/grpc-internal-error-server-panic",
  "signature": "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",
  "signature_zh": "rpc 错误：code = Internal desc = grpc: 服务器无法编码响应：rpc 错误：code = Internal desc = grpc: 编组时出错：proto: 使用 nil 调用 Marshal",
  "regex": "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",
  "domain": "go",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "The server handler returned a nil response message, and the gRPC framework attempted to marshal it, causing a panic or error.",
  "root_cause_type": "generic",
  "root_cause_zh": "服务器处理程序返回了 nil 响应消息，gRPC 框架尝试编组它，导致 panic 或错误。",
  "versions": [
    {
      "version": "1.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Recovering from the panic without fixing the nil response still results in an error sent to the client.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Returning an empty message may be semantically incorrect and does not address the root cause.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "func (s *server) YourMethod(ctx context.Context, req *pb.Request) (*pb.Response, error) {\n    // Always return a valid response\n    return &pb.Response{}, nil\n}",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "func validateResponseInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {\n    resp, err := handler(ctx, req)\n    if err != nil { return nil, err }\n    if resp == nil { return nil, status.Error(codes.Internal, \"nil response\") }\n    return resp, nil\n}",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": null,
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-09-10",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}