{"record":{"id":"6f7a4640a618e556","repo":"AlexxIT/go2rtc","slug":"hap-wrong-request-v","errorCode":null,"errorMessage":"hap: wrong request: %#v","messagePattern":"hap: wrong request: %#v","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/hap/helpers.go","lineNumber":125,"sourceCode":"\treturn base64.StdEncoding.EncodeToString(b[:4])\n}\n\nfunc Append(items ...any) (b []byte) {\n\tfor _, item := range items {\n\t\tswitch v := item.(type) {\n\t\tcase string:\n\t\t\tb = append(b, v...)\n\t\tcase []byte:\n\t\t\tb = append(b, v[:]...)\n\t\tdefault:\n\t\t\tpanic(v)\n\t\t}\n\t}\n\treturn\n}\n\nfunc newRequestError(req any) error {\n\treturn fmt.Errorf(\"hap: wrong request: %#v\", req)\n}\n\nfunc newResponseError(req, res any) error {\n\treturn fmt.Errorf(\"hap: wrong response: %#v, on request: %#v\", res, req)\n}\n","sourceCodeStart":107,"sourceCodeEnd":131,"githubUrl":"https://github.com/AlexxIT/go2rtc/blob/c245815e75e2a5fd60b4290f12bfc04e55a984d3/pkg/hap/helpers.go#L107-L131","documentation":"newRequestError signals that a HAP pair-setup or pair-verify step received an unexpected/invalid request payload. The %#v verb dumps the full Go representation of the offending request for debugging. It is a protocol-shape guard inside the HomeKit pairing state machine.","triggerScenarios":"PairSetup or PairVerify is invoked with a request TLV/body that does not match the expected structure for the current pairing step (e.g. wrong sub-type, missing fields, client sending verify body to setup handler).","commonSituations":"A custom or third-party HomeKit client speaking the HAP protocol incorrectly; replaying a request from a different pairing stage; intercepting/proxying HAP traffic that corrupts the TLV body.","solutions":["Verify the client sends a correctly formed TLV8 body with the right kTLVType_Request (0=PairSetup, 1=PairVerify) for the endpoint.","Ensure the request is routed to the correct handler: /pair-setup vs /pair-verify.","Inspect the %#v dump of the request to see which fields are missing or wrong.","Re-run pairing from scratch; partial/corrupted pairing sessions produce out-of-order requests."],"exampleFix":"// before (client sends verify-style body to setup)\nres, _ := http.Post(base+\"/pair-verify\", ...)\n// after\nres, _ := http.Post(base+\"/pair-setup\", \"application/octet-stream\", tlvPairSetupBody)","handlingStrategy":"try-catch","validationCode":"// client-side: ensure TLV body contains kTLVType_Request matching the endpoint before sending","typeGuard":"// Go server-side: validate req structure with a shape check before the state machine\nif req.Method != expectedMethod { return newRequestError(req) }","tryCatchPattern":"if err := session.PairVerify(body); err != nil {\n    var reqErr *fmt.Errorf\n    log.Printf(\"pair request rejected: %v\", err) // includes %#v dump\n    restartPairing()\n}","preventionTips":["Always start a fresh pairing session instead of replaying old requests","Route /pair-setup and /pair-verify bodies to their exact handlers","Test clients against the HAP spec TLV layouts","Log the full request dump when iterating on protocol code"],"tags":["go","hap","homekit","protocol"],"backgroundTag":"unexpected-api-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"}