go data_error ai_generated true

proto: (field mask): invalid path "user..name"

ID: go/proto-field-mask-path-invalid

Also available as: JSON · Markdown · 中文
80%Fix Rate
85%Confidence
0Evidence
2024-10-04First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
google.golang.org/protobuf v1.31+ active — — —

Root Cause

fieldmaskpb validation rejected a path with empty segments or names not present in the message descriptor.

generic

中文

fieldmaskpb 验证拒绝了包含空段或消息描述符中不存在的字段名的路径。

Workarounds

  1. 92% success
    fm := &fieldmaskpb.FieldMask{Paths: []string{"user.name", "user.email"}}
    fm.Normalize()
    if !fm.IsValid(msg) {
        return nil, status.Error(codes.InvalidArgument, "invalid field mask")
    }
  2. 85% success
    md := msg.ProtoReflect().Descriptor()
    for _, p := range fm.Paths {
        if !fieldMaskPathExists(md, p) {
            return nil, fmt.Errorf("unknown field: %s", p)
        }
    }

Dead Ends

Common approaches that don't work:

  1. 80% fail

    Silently changes semantics; the Update RPC will apply the wrong field mask.

  2. 75% fail

    Loses protobuf descriptor validation and interop with other gRPC clients.