go data_error ai_generated true

rpc error: code = InvalidArgument desc = invalid enum value: 42 for field 'status', expected 0-3

ID: go/grpc-invalid-argument-enum-value

Also available as: JSON · Markdown · 中文
80%Fix Rate
88%Confidence
0Evidence
2025-11-20First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1.0 active — — —
1.1 active — — —

Root Cause

The client sent an integer value that does not correspond to any valid enum constant defined in the protobuf schema.

generic

中文

客户端发送了一个整数,该整数不对应protobuf模式中定义的任何有效枚举常量。

Workarounds

  1. 95% success Ensure the enum value is within the defined set.
    validStatuses := map[int32]bool{0: true, 1: true, 2: true, 3: true}
    if !validStatuses[req.Status] {
        return fmt.Errorf("invalid status: %d", req.Status)
    }
  2. 90% success Use the generated enum constants from protobuf.
    req.Status = pb.Status_ACTIVE // Use the constant instead of raw integer

Dead Ends

Common approaches that don't work:

  1. Ignore the error and assume the server will accept any integer. 100% fail

    The server validates enum values; invalid ones are rejected.

  2. Use a random integer within the range hoping it matches. 90% fail

    Only specific integers are valid enum values; random ones will likely be invalid.