chenhg5/cc-connect · error

yuanbao: unknown wire type %d at %d

Error message

yuanbao: unknown wire type %d at %d

What it means

Thrown by parseFields when a field tag carries a wire type outside the supported set {0 (varint), 1 (64-bit), 2 (length-delimited), 5 (32-bit)} — e.g. 3/4 (deprecated groups) or an impossible value. Either the server is sending protobuf features this hand-rolled decoder doesn't implement, or the cursor is desynchronized and reading mid-field bytes as a tag.

Source

Thrown at platform/yuanbao/proto.go:179

			}
			val := make([]byte, ln)
			copy(val, data[pos:pos+int(ln)])
			fields = append(fields, field{fieldNum, wt, val})
			pos += int(ln)
		case wt64Bit:
			if pos+8 > len(data) {
				return nil, fmt.Errorf("yuanbao: 64-bit truncated at %d", pos)
			}
			fields = append(fields, field{fieldNum, wt, binary.LittleEndian.Uint64(data[pos : pos+8])})
			pos += 8
		case wt32Bit:
			if pos+4 > len(data) {
				return nil, fmt.Errorf("yuanbao: 32-bit truncated at %d", pos)
			}
			fields = append(fields, field{fieldNum, wt, uint64(binary.LittleEndian.Uint32(data[pos : pos+4]))})
			pos += 4
		default:
			return nil, fmt.Errorf("yuanbao: unknown wire type %d at %d", wt, pos)
		}
	}
	return fields, nil
}

func decodeVarint(data []byte) (uint64, int) {
	var result uint64
	var shift uint
	for i, b := range data {
		result |= uint64(b&0x7F) << shift
		shift += 7
		if b&0x80 == 0 {
			return result, i + 1
		}
		if shift >= 64 {
			return 0, 0
		}
	}

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Log the wire type and offset; wire types 3/4 mean the server uses groups — extend parseFields to handle or skip SGROUP/EGROUP.
  2. Verify the payload actually is raw protobuf (not gzipped/JSON) before decoding.
  3. Resync from the frame boundary: reconnect or skip to the next frame after this error rather than continuing the stream.
  4. Compare against a reference protobuf decode (protoc --decode_raw) of a captured frame to see what changed.
  5. Pin/inspect the yuanbao server version for wire-format changes.

Example fix

// before
case wt32Bit:
    ...
default:
    return nil, fmt.Errorf("yuanbao: unknown wire type %d at %d", wt, pos)
// after
case wtSGROUP: // wire type 3: skip nested group until matching EGROUP
    n, err := skipGroup(data[pos:], fieldNum)
    if err != nil { return nil, err }
    pos += n
default:
    return nil, fmt.Errorf("yuanbao: unknown wire type %d at %d", wt, pos)
Defensive patterns

Strategy: try-catch

Type guard

func supportedWireType(wt int) bool {
    switch wt { case 0, 1, 2, 5: return true }
    return false
}

Try / catch

fields, err := parseFields(data)
if err != nil {
    var werr *wireTypeError
    if errors.As(err, &werr) && werr.WireType == 3 {
        // extend decoder to support groups or upgrade adapter
    }
    stream.Resync()
    return
}

Prevention

When it happens

Trigger: Server starts using group fields (wire types 3/4) or a packed/new encoding not in the switch; or an earlier field's length was misparsed so the cursor lands on non-tag bytes producing a bogus wire type. Reached from all yuanbao decode paths.

Common situations: Yuanbao server protocol update introducing unsupported wire types; decoding non-protobuf bytes (e.g. a JSON or gzip body) as protobuf; frame boundary bugs causing desync.

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 chenhg5/cc-connect@4000b2338a (2026-09-06). Data as JSON: /api/errors/3777117b2c1217f1. Report an issue: GitHub.