{
  "id": "go/proto-marshal-nil-message",
  "signature": "panic: proto: Marshal called with nil",
  "signature_zh": "panic：proto：以 nil 调用 Marshal",
  "regex": "panic:\\ proto:\\ Marshal\\ called\\ with\\ nil",
  "domain": "go",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "google.golang.org/protobuf Marshal/Unmarshal was called with a nil proto.Message, typically a nil pointer returned from a function that was supposed to build a request.",
  "root_cause_type": "generic",
  "root_cause_zh": "以 nil 的 proto.Message 调用 google.golang.org/protobuf 的 Marshal/Unmarshal，通常是本应构建请求的函数返回了 nil 指针。",
  "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": "Recovering hides the nil bug; the request is still malformed and downstream calls fail silently.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "proto.Clone(nil) also panics with the same message.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "Guard against nil before marshaling:\nif req == nil {\n    return status.Error(codes.InvalidArgument, \"request is nil\")\n}\n_ = req.ProtoReflect().IsValid()",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "Return value types instead of pointers from builders, or always allocate:\nreq := &pb.GetUserRequest{}\nif userID != \"\" { req.Id = userID }",
      "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.86,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-05-02",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}