go data_error ai_generated true

proto: required field "pb.User.id" not set

ID: go/protobuf-required-field-missing

Also available as: JSON · Markdown · 中文
80%Fix Rate
83%Confidence
0Evidence
2025-06-30First Seen

Version Compatibility

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

Root Cause

A message defined with proto2 `required` fields was marshaled or unmarshaled without the required field set. Proto3 has no required fields, so this only occurs with proto2 or gogo/protobuf.

generic

中文

定义了 proto2 `required` 字段的消息在序列化或反序列化时未设置必填字段。proto3 没有必填字段,因此这只发生在 proto2 或 gogo/protobuf 中。

Workarounds

  1. 90% success
    id := int64(42)
    msg := &pb.User{Id: &id}
    if err := proto.Marshal(msg); err != nil { return err }
  2. 85% success
    // user.proto (proto3)
    message User {
      optional int64 id = 1;
    }

Dead Ends

Common approaches that don't work:

  1. 80% fail

    proto2 treats zero value as unset for scalar required fields; still fails.

  2. 50% fail

    Breaking change for existing wire consumers; migration is non-trivial.