{"record":{"id":"d1fe070b40f627c0","repo":"chenhg5/cc-connect","slug":"yuanbao-empty-data","errorCode":null,"errorMessage":"yuanbao: empty data","messagePattern":"yuanbao: empty data","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"platform/yuanbao/proto.go","lineNumber":133,"sourceCode":"func encodeConnMsgFull(cmdType int, cmd string, seqNo int, msgID string, module string, data []byte, needAck bool) []byte {\n\tb := newBuffer(128 + len(data))\n\theadBytes := (&buffer{}).writeHead(cmdType, cmd, seqNo, msgID, module, needAck, 0)\n\tb.writeBytesField(1, headBytes)\n\tif len(data) > 0 {\n\t\tb.writeBytesField(2, data)\n\t}\n\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})","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/yuanbao/proto.go#L115-L151","documentation":"parseFields is the low-level protobuf wire-format decoder for yuanbao frames; it rejects empty input with this error because there are no fields to parse. It indicates an upstream frame/message body that should contain data arrived empty.","triggerScenarios":"decodeConnMsg, decodeAuthBindRsp, decodeInboundPush, or decodeMsgBodyElement passing a zero-length byte slice into parseFields — e.g. an empty push payload from the server or a failed decrypt/decompress yielding no bytes.","commonSituations":"Server sends a heartbeat/ack frame with an empty body that the decoder incorrectly routes through a decode path expecting data; decompression or decryption step produced empty output; truncated network frame.","solutions":["Log the raw frame before decoding to see whether the server genuinely sent an empty body","Check the decompress/decrypt step upstream — empty output there usually means wrong key or corrupt payload","Guard decode paths to skip parseFields when the payload is legitimately empty (e.g. pure ack frames)","Retry the connection if the server persistently sends malformed frames"],"exampleFix":"// before\nfields, err := parseFields(body)\n// after\nif len(body) == 0 { return nil } // empty ack frame, nothing to parse\nfields, err := parseFields(body)","handlingStrategy":"try-catch","validationCode":"if len(data) == 0 { return nil /* nothing to parse */ }","typeGuard":null,"tryCatchPattern":"fields, err := parseFields(data); if err != nil { if strings.Contains(err.Error(), \"empty data\") { return nil /* tolerate empty frames */ }; return fmt.Errorf(\"decode: %w\", err) }","preventionTips":["Skip empty payloads before invoking decoders","Log raw frames at debug level to diagnose empty bodies","Verify decrypt/decompress output is non-empty before parsing","Add decode tests covering empty and truncated frames"],"tags":["protobuf","decoding","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"}