{
  "id": "go/protobuf-marshal-nil-message",
  "signature": "proto: Marshal called with nil message",
  "signature_zh": "proto: Marshal 被传入 nil 消息",
  "regex": "proto:\\ Marshal\\ called\\ with\\ nil\\ message",
  "domain": "go",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "A typed nil proto message (e.g. (*pb.User)(nil)) was passed to proto.Marshal, or a typed-nil interface was stored and later marshaled.",
  "root_cause_type": "generic",
  "root_cause_zh": "向 proto.Marshal 传入了类型化的 nil proto 消息（如 (*pb.User)(nil)），或将类型化 nil 接口存储后进行了序列化。",
  "versions": [
    {
      "version": "google.golang.org/protobuf v1.26+",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "proto.Marshal returns an error rather than panicking; recover does not catch returned errors.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "The legacy package delegates to the new one and exhibits the same behavior.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "if msg == nil {\n    return errors.New(\"message is nil\")\n}\nb, err := proto.Marshal(msg)\nif err != nil { return err }",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "func build() (*pb.User, error) {\n    return &pb.User{Name: \"a\"}, nil // never return (*pb.User)(nil), 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.87,
  "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": []
}