thanos-io/thanos · error

proto: Statistic: wiretype end group for non-group

Error message

proto: Statistic: wiretype end group for non-group

What it means

In the generated Unmarshal loop for the Statistic message (pkg/status/statuspb/rpc.pb.go:1846), a wire type of 4 means 'end group', which is only valid inside a group field. Since Statistic is not a group, this error indicates the byte stream is structurally invalid or produced from a different schema.

Solutions

  1. Fix the upstream schema mismatch by aligning both peers on the same generated statuspb code
  2. Re-sync parsing: if an earlier field error occurred, the stream is desynchronized — start unmarshal from the message start, not mid-buffer
  3. Validate the transport (compression, proxy) is not corrupting frames
  4. Re-marshal and hex-dump the message on the sender side to compare against the receiver's expectations

Example fix

// before: parsing mid-buffer
msg.Unmarshal(buf[offset:])
// after
msg.Unmarshal(buf) // start from the full serialized message
Defensive patterns

Strategy: try-catch

Validate before calling

if len(buf) == 0 || buf[0] == 0 {
    return errors.New("empty or malformed protobuf frame")
}

Try / catch

if err := proto.Unmarshal(buf, &stat); err != nil {
    if strings.Contains(err.Error(), "end group for non-group") {
        return fmt.Errorf("corrupt or desynchronized protobuf frame: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: Unmarshaling bytes where the tag for the next field of Statistic has wire type 4 — caused by desynchronized parsing (an earlier field consumed the wrong number of bytes), group-encoded data, or a corrupted payload.

Common situations: Corrupted/truncated gRPC response bodies; a sender built from an incompatible .proto that shifts field boundaries so the receiver reads a tag mid-field; reusing a marshaled buffer incorrectly.

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/7b4d01bedf0ffe49. Report an issue: GitHub.

Appendix: source

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

		var wire uint64
		for shift := uint(0); ; shift += 7 {
			if shift >= 64 {
				return ErrIntOverflowRpc
			}
			if iNdEx >= l {
				return io.ErrUnexpectedEOF
			}
			b := dAtA[iNdEx]
			iNdEx++
			wire |= uint64(b&0x7F) << shift
			if b < 0x80 {
				break
			}
		}
		fieldNum := int32(wire >> 3)
		wireType := int(wire & 0x7)
		if wireType == 4 {
			return fmt.Errorf("proto: Statistic: wiretype end group for non-group")
		}
		if fieldNum <= 0 {
			return fmt.Errorf("proto: Statistic: illegal tag %d (wire type %d)", fieldNum, wire)
		}
		switch fieldNum {
		case 1:
			if wireType != 2 {
				return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType)
			}
			var stringLen uint64
			for shift := uint(0); ; shift += 7 {
				if shift >= 64 {
					return ErrIntOverflowRpc
				}
				if iNdEx >= l {
					return io.ErrUnexpectedEOF
				}
				b := dAtA[iNdEx]

View on GitHub (pinned to 35b8b99117)