go type_error ai_generated true

rpc error: code = InvalidArgument desc = expected string, got number for field age

ID: go/grpc-invalid-argument-field-type

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

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1.56.x active
1.57.x active

Root Cause

The protobuf message field type mismatch; e.g., sending an integer where a string is expected.

generic

中文

protobuf 消息字段类型不匹配;例如,在期望字符串的地方发送了整数。

Workarounds

  1. 95% success
    string age = 1; protoc --go_out=. *.proto
  2. 90% success
    req := &pb.Person{Age: strconv.Itoa(30)}
  3. 85% success
    if _, ok := req.Age.(string); !ok { return status.Error(codes.InvalidArgument, "age must be string") }

Dead Ends

Common approaches that don't work:

  1. Continuing to send incorrect type. 100% fail

    Same error persists.

  2. Using type assertion without changing proto. 80% fail

    Proto definition determines wire format.

  3. Blaming server for type checking. 50% fail

    Client must follow proto definition.