{"record":{"id":"06644035def6bf0e","repo":"chenhg5/cc-connect","slug":"yuanbao-parse-varint-tag-failed-at-d","errorCode":null,"errorMessage":"yuanbao: parse varint tag failed at %d","messagePattern":"yuanbao: parse varint tag failed at (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/yuanbao/proto.go","lineNumber":140,"sourceCode":"\treturn b.bytes()\n}\n\ntype field struct {\n\tfieldNum int\n\twireType int\n\tvalue    interface{}\n}\n\nfunc parseFields(data []byte) ([]field, error) {\n\tif len(data) == 0 {\n\t\treturn nil, fmt.Errorf(\"yuanbao: empty data\")\n\t}\n\tvar fields []field\n\tpos := 0\n\tfor pos < len(data) {\n\t\ttag, n := decodeVarint(data[pos:])\n\t\tif n == 0 {\n\t\t\treturn nil, fmt.Errorf(\"yuanbao: parse varint tag failed at %d\", pos)\n\t\t}\n\t\tpos += n\n\t\tfieldNum := int(tag >> 3)\n\t\twt := int(tag & 0x07)\n\t\tswitch wt {\n\t\tcase wtVarint:\n\t\t\tval, n := decodeVarint(data[pos:])\n\t\t\tif n == 0 {\n\t\t\t\treturn nil, fmt.Errorf(\"yuanbao: parse varint at %d\", pos)\n\t\t\t}\n\t\t\tfields = append(fields, field{fieldNum, wt, val})\n\t\t\tpos += n\n\t\tcase wtLen:\n\t\t\tln, n := decodeVarint(data[pos:])\n\t\t\tif n == 0 {\n\t\t\t\treturn nil, fmt.Errorf(\"yuanbao: parse length at %d\", pos)\n\t\t\t}\n\t\t\tpos += n","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/yuanbao/proto.go#L122-L158","documentation":"This error is thrown by parseFields in the yuanbao protocol codec when the protobuf wire-format tag at the current byte offset cannot be decoded as a varint. decodeVarint returns n==0 when the buffer ends mid-varint (continuation bit set on the last byte) or the varint exceeds 10 bytes, meaning the framed payload is not valid protobuf data.","triggerScenarios":"decodeVarint(data[pos:]) returns 0 while parsing the tag of a message frame: input shorter than the tag's varint length, byte 0x80+ as the final byte, or a 10+ byte malformed varint. Reached via decodeConnMsg, decodeAuthBindRsp, decodeInboundPush, or decodeMsgBodyElement on any inbound frame.","commonSituations":"Yuanbao server protocol changed (new framing/wire format), a truncated or corrupted WebSocket frame is fed to the decoder, a caller accidentally passes plaintext or compressed data instead of the protobuf body, or a proxy splits/merges frames incorrectly.","solutions":["Verify the bytes passed to parseFields are the complete, uncompressed protobuf message for the frame (check framing/splitting logic upstream of decodeConnMsg).","Log the raw bytes at the failure offset and compare against an expected encoded message to detect protocol drift after a server update.","Update the yuanbao adapter to match any changed server protocol version.","Add a length/consistency check before decoding: ensure the frame payload length matches the header-declared length.","If transient network truncation is suspected, reconnect and re-request the frame rather than retrying the parse."],"exampleFix":"// before\nraw := wsFrame.Payload\ncmp, _ := parseFields(raw)\n// after\nif len(raw) == 0 || raw[len(raw)-1]&0x80 != 0 {\n    return fmt.Errorf(\"frame truncated, refusing to parse\")\n}\ncmp, err := parseFields(raw)\nif err != nil {\n    return fmt.Errorf(\"yuanbao: decode frame: %w\", err)\n}","handlingStrategy":"validation","validationCode":"func isDecodableFrame(b []byte) bool {\n    return len(b) > 0 && b[len(b)-1]&0x80 == 0\n}","typeGuard":"func validVarintStart(b []byte) bool {\n    // tag varint must terminate within 10 bytes\n    n := 0\n    for n < len(b) && n < 10 {\n        if b[n]&0x80 == 0 { return true }\n        n++\n    }\n    return false\n}","tryCatchPattern":"cm, err := decodeConnMsg(raw)\nif err != nil {\n    slog.Warn(\"yuanbao: drop frame\", \"err\", err)\n    return // or resync/reconnect\n}","preventionTips":["Always read the complete frame (declared length) before decoding.","Never feed compressed or encrypted bodies directly to the decoder.","Re-sync from the frame boundary after any parse error instead of continuing.","Dump raw bytes on failure to detect server protocol drift early.","Add fuzz/round-trip tests for the wire codec."],"tags":["protobuf","wire-format","parsing","yuanbao"],"backgroundTag":"protobuf-unmarshal-failed","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}