go runtime_error ai_generated true

panic: proto: field pb.User.labels contains invalid nil map value

ID: go/protobuf-marshal-nil-map

Also available as: JSON · Markdown · 中文
80%Fix Rate
84%Confidence
0Evidence
2025-08-25First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
google.golang.org/protobuf 1.x active — — —

Root Cause

A proto map field was assigned a map with a nil value (e.g. map[string]*Meta{"k": nil}), which the protobuf runtime rejects during marshal.

generic

中文

proto map 字段被赋值为包含 nil 值的 map(如 map[string]*Meta{"k": nil}),protobuf 运行时在序列化时拒绝该值。

Workarounds

  1. 92% success
    labels := make(map[string]*pb.Meta)
    for k, v := range src {
      if v == nil { continue }
      labels[k] = v
    }
    msg.Labels = labels
  2. 88% success
    // user.proto
    message User {
      map<string, Meta> labels = 1;
    }

Dead Ends

Common approaches that don't work:

  1. 85% fail

    Swallowing the panic leaves the message unsent and corrupts control flow.

  2. 70% fail

    Data loss and hidden bugs; the caller has no signal that data was dropped.