{"record":{"id":"4a17c0261ba4c6a5","repo":"chenhg5/cc-connect","slug":"yuanbao-parse-varint-at-d","errorCode":null,"errorMessage":"yuanbao: parse varint at %d","messagePattern":"yuanbao: parse varint at (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/yuanbao/proto.go","lineNumber":149,"sourceCode":"func 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\n\t\t\tif pos+int(ln) > len(data) {\n\t\t\t\treturn nil, fmt.Errorf(\"yuanbao: length %d exceeds data at %d\", ln, pos)\n\t\t\t}\n\t\t\tval := make([]byte, ln)\n\t\t\tcopy(val, data[pos:pos+int(ln)])\n\t\t\tfields = append(fields, field{fieldNum, wt, val})\n\t\t\tpos += int(ln)\n\t\tcase wt64Bit:\n\t\t\tif pos+8 > len(data) {","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/yuanbao/proto.go#L131-L167","documentation":"Thrown by parseFields when the value varint for a field with wire type wtVarint cannot be decoded at the current offset. Like the tag error, decodeVarint returned n==0 because the buffer ends mid-varint or the varint is malformed (overlong, >10 bytes). The tag was parsed successfully but the payload is truncated right after it.","triggerScenarios":"A protobuf message whose last field is a varint but whose bytes are cut off after the tag — e.g. a truncated frame from the WebSocket, or a length-prefixed sub-message whose declared length exceeds the available bytes. Hit on any decodeConnMsg/decodeAuthBindRsp/decodeInboundPush/decodeMsgBodyElement path.","commonSituations":"Network layer delivered a partial frame, a bug in the caller's slice bounds chopped the message tail, or server-side serialization changed producing incompatible payloads.","solutions":["Check that the full frame body was read before decoding (compare bytes read vs. frame length header).","Log offset pos and the remaining bytes to confirm truncation, then fix the upstream read loop to buffer until the frame is complete.","Re-request the message from the server (reconnect) since truncated data is unrecoverable.","Verify the yuanbao server protocol version hasn't changed the field encoding."],"exampleFix":"// before\nval, n := decodeVarint(data[pos:])\nif n == 0 {\n    return nil, fmt.Errorf(\"yuanbao: parse varint at %d\", pos)\n}\n// after (caller side: ensure complete frame)\nif len(buf) < frameLen {\n    return nil, io.ErrUnexpectedEOF // wait for more bytes instead of parsing\n}\nval, n := decodeVarint(data[pos:])\nif n == 0 {\n    return nil, fmt.Errorf(\"yuanbao: parse varint at %d\", pos)\n}","handlingStrategy":"validation","validationCode":"if len(frame.Payload) < frame.DeclaredLen {\n    return errors.New(\"frame incomplete, do not decode\")\n}","typeGuard":null,"tryCatchPattern":"fields, err := parseFields(data)\nif err != nil {\n    slog.Warn(\"malformed varint payload\", \"offset\", pos, \"err\", err)\n    conn.Reconnect()\n    return\n}","preventionTips":["Buffer until the full frame arrives before parsing.","Check the last byte of a varint field has the continuation bit cleared where the schema allows.","Log offset + hex dump on failure for diagnosis.","Reconnect after truncation rather than re-parsing stale buffers."],"tags":["protobuf","wire-format","truncated-data","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-14T05:17:10.506Z"}