thanos-io/thanos · error

proto: illegal wireType

Error message

proto: illegal wireType %d

What it means

This error comes from gogo/golang generated protobuf unmarshal code in rpc.pb.go. When decoding a length-delimited or varint-encoded field, the wire type read from the tag byte must be one of 0-5; any other value means the byte stream is not a valid protobuf message. The generated skip function returns this error instead of silently misparsing corrupt data.

Solutions

  1. Verify the bytes being unmarshaled are actual protobuf wire format (not JSON, gzip, or truncated data).
  2. Regenerate or re-align the .pb.go files so both producer and consumer use the same proto schema version.
  3. Add checksum/length validation on the transport layer before calling Unmarshal.
  4. Log the first bytes of the failing payload to confirm it starts with a valid protobuf field tag.

Example fix

// before
if err := proto.Unmarshal(data, msg); err != nil { return err }
// after
if len(data) == 0 { return errors.New("empty payload") }
if err := proto.Unmarshal(data, msg); err != nil {
    return errors.Wrapf(err, "invalid protobuf payload (first bytes: %x)", data[:min(8, len(data))])
}
Defensive patterns

Strategy: validation

Validate before calling

func validProtobufPayload(data []byte) bool {
    if len(data) == 0 { return false }
    tag, n := binary.Uvarint(data)
    return n > 0 && tag>>3 > 0 && tag&0x7 <= 5
}

Prevention

When it happens

Trigger: Unmarshaling a protobuf message (here from pkg/status/statuspb or pkg/exemplars/exemplarspb) whose bytes were truncated, corrupted, or are not protobuf at all, so the parsed wireType in the skip loop falls outside the known range 0-5.

Common situations: Sending non-protobuf payloads to an endpoint expecting protobuf, mixing incompatible proto schema versions between client and server, or feeding compressed/garbage bytes into proto.Unmarshal.

Understand the failure class

Background: "cannot parse invalid wire-format data", "cannot unmarshal", "failed unmarshalling": protobuf unmarshal errors explained — this error's family across 10 libraries.

Related errors


AI-assisted analysis of thanos-io/thanos@35b8b99117 (2026-09-07). Data as JSON: /api/errors/8c1a4fdbdbcd4b71. Report an issue: GitHub.

Appendix: source

Thrown at pkg/status/statuspb/rpc.pb.go:1991

				if b < 0x80 {
					break
				}
			}
			if length < 0 {
				return 0, ErrInvalidLengthRpc
			}
			iNdEx += length
		case 3:
			depth++
		case 4:
			if depth == 0 {
				return 0, ErrUnexpectedEndOfGroupRpc
			}
			depth--
		case 5:
			iNdEx += 4
		default:
			return 0, fmt.Errorf("proto: illegal wireType %d", wireType)
		}
		if iNdEx < 0 {
			return 0, ErrInvalidLengthRpc
		}
		if depth == 0 {
			return iNdEx, nil
		}
	}
	return 0, io.ErrUnexpectedEOF
}

var (
	ErrInvalidLengthRpc        = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowRpc          = fmt.Errorf("proto: integer overflow")
	ErrUnexpectedEndOfGroupRpc = fmt.Errorf("proto: unexpected end of group")
)

View on GitHub (pinned to 35b8b99117)