{
  "id": "go/proto-nil-message-fields",
  "signature": "panic: proto: Marshal called with nil",
  "signature_zh": "panic：proto：Marshal 调用时传入 nil",
  "regex": "panic:\\ proto:\\ Marshal\\ called\\ with\\ nil",
  "domain": "go",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "proto.Marshal was called with a nil *Message pointer. This happens when an uninitialized message field or a nil response is passed directly to Marshal.",
  "root_cause_type": "generic",
  "root_cause_zh": "调用 proto.Marshal 时传入了 nil 的 *Message 指针。当未初始化的消息字段或 nil 响应直接传给 Marshal 时发生。",
  "versions": [
    {
      "version": "google.golang.org/protobuf 1.28+",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "The nil message indicates a logic bug; swallowing the panic leaves a corrupt state and the message is never sent, causing silent data loss.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Marshalling an empty struct produces an empty byte slice, which downstream code interprets as a valid but empty message, corrupting semantics.",
      "fail_rate": 0.75,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "Guard against nil before marshalling:\nif msg == nil {\n    return nil, status.Error(codes.Internal, \"nil message\")\n}\nb, err := proto.Marshal(msg)\nif err != nil { return nil, err }",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "Initialize nested message fields with proto message constructors instead of leaving them nil:\nresp := &pb.Response{Data: &pb.Data{}} // not just &pb.Response{}",
      "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.89,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-01-22",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}