{
  "id": "go/protobuf-proto-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": "runtime_error",
  "subcategory": null,
  "root_cause": "A nil protobuf message pointer was passed to proto.Marshal or protojson.Marshal, typically from a handler that returned a nil pointer on error paths without checking.",
  "root_cause_type": "generic",
  "root_cause_zh": "向 proto.Marshal 或 protojson.Marshal 传入了 nil 的 protobuf 消息指针，通常源自处理器在错误路径返回 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": "Swallowing the panic leaves the caller with no message and no error, causing silent data loss downstream.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Changes wire semantics; clients expecting a specific message type get an unrelated type and may fail to unmarshal.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "if msg == nil {\n    return nil, status.Error(codes.Internal, \"nil message\")\n}\nb, err := proto.Marshal(msg)\nif err != nil { return nil, status.Error(codes.Internal, err.Error()) }",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "func (s *srv) Get(ctx context.Context, req *pb.GetReq) (*pb.GetResp, error) {\n    if req == nil { return &pb.GetResp{}, nil }\n    return &pb.GetResp{Id: req.Id}, 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.86,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-02-15",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}