{"record":{"id":"68162246d9585060","repo":"AlexxIT/go2rtc","slug":"data-too-short-d-bytes","errorCode":null,"errorMessage":"data too short: %d bytes","messagePattern":"data too short: (.+?) bytes","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/wyze/client.go","lineNumber":470,"sourceCode":"func (c *Client) buildK10056(frameSize uint8, bitrate uint16) []byte {\n\tb := make([]byte, 21)\n\tcopy(b, \"HL\")                                           // magic\n\tb[2] = 5                                                // version\n\tbinary.LittleEndian.PutUint16(b[4:], KCmdSetResolution) // 10056\n\tbinary.LittleEndian.PutUint16(b[6:], 5)                 // payload len\n\tb[16] = frameSize + 1                                   // frame size\n\tbinary.LittleEndian.PutUint16(b[17:], bitrate)          // bitrate\n\t// b[19:21] = FPS (0 = auto)\n\treturn b\n}\n\nfunc (c *Client) parseK10001(data []byte) (challenge []byte, status byte, err error) {\n\tif c.verbose {\n\t\tfmt.Printf(\"[Wyze] parseK10001: received %d bytes\\n\", len(data))\n\t}\n\n\tif len(data) < 33 {\n\t\treturn nil, 0, fmt.Errorf(\"data too short: %d bytes\", len(data))\n\t}\n\n\tif data[0] != 'H' || data[1] != 'L' {\n\t\treturn nil, 0, fmt.Errorf(\"invalid HL magic: %x %x\", data[0], data[1])\n\t}\n\n\tcmdID := binary.LittleEndian.Uint16(data[4:])\n\tif cmdID != KCmdChallenge {\n\t\treturn nil, 0, fmt.Errorf(\"expected cmdID 10001, got %d\", cmdID)\n\t}\n\n\tstatus = data[16]\n\tchallenge = make([]byte, 16)\n\tcopy(challenge, data[17:33])\n\n\treturn challenge, status, nil\n}\n","sourceCodeStart":452,"sourceCodeEnd":488,"githubUrl":"https://github.com/AlexxIT/go2rtc/blob/c245815e75e2a5fd60b4290f12bfc04e55a984d3/pkg/wyze/client.go#L452-L488","documentation":"parseK10001 expects the HL-framed K10001 challenge payload to be at least 33 bytes (HL magic + fixed header + challenge data). If the received data is shorter, it returns \"data too short: N bytes\" so the caller doesn't index out of bounds.","triggerScenarios":"Camera replied to K10000 with an empty or minimal status frame instead of a full challenge; truncated UDP/DTLS packet; firmware sending a rejection/keepalive frame where a challenge was expected.","commonSituations":"Camera rejecting the session early with a short error frame; network corruption dropping payload bytes; firmware version whose K10001 is smaller than the expected 33-byte layout.","solutions":["Enable verbose logging to see the received byte count and dump the payload.","Confirm camera credentials and re-pair if the camera is sending rejection frames instead of challenges.","Retry the connection — a single truncated frame is often transient packet loss.","If consistently short, check firmware compatibility; the challenge format may differ from the library's expectation."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := client.Dial(); err != nil {\n    if strings.Contains(err.Error(), \"data too short\") {\n        return fmt.Errorf(\"camera sent non-challenge K10001 frame: %w\", err)\n    }\n    return err\n}","preventionTips":["Retry the connection on first occurrence — often a truncated frame","Verify credentials to avoid early rejection frames","Check firmware compatibility with the expected 33-byte K10001 layout"],"tags":["go","iot","protocol","validation"],"backgroundTag":"unexpected-response-shape","analyzedSha":"c245815e75e2a5fd60b4290f12bfc04e55a984d3","analyzedAt":"2026-09-07T11:47:02.965Z","contentChangedAt":"2026-09-07T11:47:02.965Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}