{
  "id": "go/proto-unmarshal-cannot-parse-invalid-wire-format",
  "signature": "proto: cannot parse invalid wire-format data",
  "signature_zh": "proto：无法解析无效的 wire-format 数据",
  "regex": "proto:\\ cannot\\ parse\\ invalid\\ wire\\-format\\ data",
  "domain": "go",
  "category": "data_error",
  "subcategory": null,
  "root_cause": "proto.Unmarshal received bytes that are not valid protobuf wire format for the target message type. Typical causes: the payload is JSON/plain text, it was truncated, it's a different message type, or a length-delimited field has a corrupt varint length prefix.",
  "root_cause_type": "generic",
  "root_cause_zh": "proto.Unmarshal 收到的字节对于目标消息类型不是有效的 protobuf wire format。典型原因：负载是 JSON/纯文本、被截断、是另一种消息类型，或某个长度分隔字段的 varint 长度前缀已损坏。",
  "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": "Wire-format parsing is deterministic; identical bytes always fail identically. Retrying wastes CPU and never succeeds.",
      "fail_rate": 0.98,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "If the bytes are binary protobuf, protojson will reject them; if they are JSON, the original proto.Unmarshal was simply the wrong parser choice — the fix is picking the right one, not blindly swapping.",
      "fail_rate": 0.75,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.85,
      "how": "Validate and log the raw bytes before unmarshaling, and confirm the wire type matches:\n\nif len(data) == 0 { return errors.New(\"empty payload\") }\nif err := proto.Unmarshal(data, msg); err != nil {\n    log.Printf(\"unmarshal failed, first 32 bytes: %x\", data[:min(32,len(data))])\n    return fmt.Errorf(\"bad proto payload: %w\", err)\n}",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.8,
      "how": "Ensure the sender and receiver use the same generated message and that framing (length prefix) is stripped correctly, e.g. with a length-delimited reader:\n\nr := protoio.NewDelimitedReader(conn, 1<<20)\nmsg := &pb.Foo{}\nif err := r.ReadMsg(msg); err != nil { return err }",
      "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-09",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}