{"record":{"id":"277852708324ea1b","repo":"chenhg5/cc-connect","slug":"yuanbao-parse-head-w","errorCode":null,"errorMessage":"yuanbao: parse head: %w","messagePattern":"yuanbao: parse head: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/yuanbao/proto.go","lineNumber":276,"sourceCode":"\tseqNo int\n\tdata  []byte\n}\n\nfunc decodeConnMsg(raw []byte) (*connMsg, error) {\n\tif len(raw) == 0 {\n\t\treturn nil, fmt.Errorf(\"yuanbao: empty conn msg\")\n\t}\n\tfields, err := parseFields(raw)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\theadBytes := getBytes(fields, 1)\n\tpayload := getBytes(fields, 2)\n\tvar head connHead\n\tif len(headBytes) > 0 {\n\t\thf, err := parseFields(headBytes)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"yuanbao: parse head: %w\", err)\n\t\t}\n\t\thead = connHead{\n\t\t\tcmdType: int(getVarint(hf, 1)),\n\t\t\tcmd:     getString(hf, 2),\n\t\t\tseqNo:   int(getVarint(hf, 3)),\n\t\t\tmsgID:   getString(hf, 4),\n\t\t\tmodule:  getString(hf, 5),\n\t\t\tneedAck: getVarint(hf, 6) != 0,\n\t\t\tstatus:  int(getVarint(hf, 10)),\n\t\t}\n\t}\n\treturn &connMsg{head: head, seqNo: head.seqNo, data: payload}, nil\n}\n\ntype authBindRsp struct {\n\tcode      int\n\tmessage   string\n\tconnectID string","sourceCodeStart":258,"sourceCodeEnd":294,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/yuanbao/proto.go#L258-L294","documentation":"Thrown by decodeConnMsg when parsing the nested connHead sub-message (field 1) fails; the underlying parseFields error is wrapped with %w. The outer message parsed, but its header bytes are malformed protobuf, so the command/sequence metadata cannot be extracted.","triggerScenarios":"The bytes returned by getBytes(fields, 1) are not valid protobuf — server changed the head encoding, the head field got corrupted in transit, or the outer parse desynchronized and grabbed wrong bytes as the head. Callers: authenticate, handleFrame.","commonSituations":"Yuanbao server protocol update altering connHead fields; a proxy corrupting small header payloads; a bug where a varint field value is passed instead of its bytes to the head parser.","solutions":["Log the wrapped inner error plus a hex dump of headBytes to identify which head field breaks parsing.","Verify getBytes(fields, 1) returns the correct field — dump all outer fields to check the outer parse didn't desync.","Capture a frame from the server and decode with protoc --decode_raw to compare against the adapter's connHead layout.","Update the adapter's head structure if the server protocol changed.","If corruption in transit is suspected, reconnect and re-authenticate."],"exampleFix":"// before\nhf, err := parseFields(headBytes)\nif err != nil {\n    return nil, fmt.Errorf(\"yuanbao: parse head: %w\", err)\n}\n// after (caller: diagnose + tolerate)\ncm, err := decodeConnMsg(raw)\nif err != nil && strings.Contains(err.Error(), \"parse head\") {\n    slog.Warn(\"yuanbao: malformed head\", \"head\", hex.Dump(headBytes), \"err\", err)\n    return nil // drop frame; keep connection alive\n}","handlingStrategy":"try-catch","validationCode":"func headPresent(fields []field) bool {\n    h := getBytes(fields, 1)\n    return len(h) > 0\n}","typeGuard":null,"tryCatchPattern":"cm, err := decodeConnMsg(raw)\nif err != nil {\n    if strings.Contains(err.Error(), \"parse head\") {\n        slog.Warn(\"yuanbao: malformed head, dropping frame\", \"err\", err,\n            \"inner\", errors.Unwrap(err))\n        return nil\n    }\n    return err\n}","preventionTips":["Log the inner wrapped error and head bytes hex dump for every failure.","Cross-check connHead layout against protoc --decode_raw after server updates.","Validate outer fields before parsing nested head.","Keep a golden-frame fixture test for authenticate."],"tags":["protobuf","nested-message","protocol-compat","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"}