AlexxIT/go2rtc · error

hap: wrong request: %#v

Error message

hap: wrong request: %#v

What it means

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.

Solutions

  1. Verify the client sends a correctly formed TLV8 body with the right kTLVType_Request (0=PairSetup, 1=PairVerify) for the endpoint.
  2. Ensure the request is routed to the correct handler: /pair-setup vs /pair-verify.
  3. Inspect the %#v dump of the request to see which fields are missing or wrong.
  4. Re-run pairing from scratch; partial/corrupted pairing sessions produce out-of-order requests.

Example fix

// before (client sends verify-style body to setup)
res, _ := http.Post(base+"/pair-verify", ...)
// after
res, _ := http.Post(base+"/pair-setup", "application/octet-stream", tlvPairSetupBody)
Defensive patterns

Strategy: try-catch

Validate before calling

// client-side: ensure TLV body contains kTLVType_Request matching the endpoint before sending

Type guard

// Go server-side: validate req structure with a shape check before the state machine
if req.Method != expectedMethod { return newRequestError(req) }

Try / catch

if err := session.PairVerify(body); err != nil {
    var reqErr *fmt.Errorf
    log.Printf("pair request rejected: %v", err) // includes %#v dump
    restartPairing()
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Understand the failure class

Background: "invalid response format", "malformed payload", "missing data field": when an API returns 200 but the response shape is wrong — this error's family across 23 libraries.

Related errors


AI-assisted analysis of AlexxIT/go2rtc@c245815e75 (2026-09-07). Data as JSON: /api/errors/6f7a4640a618e556. Report an issue: GitHub.

Appendix: source

Thrown at pkg/hap/helpers.go:125

	return base64.StdEncoding.EncodeToString(b[:4])
}

func Append(items ...any) (b []byte) {
	for _, item := range items {
		switch v := item.(type) {
		case string:
			b = append(b, v...)
		case []byte:
			b = append(b, v[:]...)
		default:
			panic(v)
		}
	}
	return
}

func newRequestError(req any) error {
	return fmt.Errorf("hap: wrong request: %#v", req)
}

func newResponseError(req, res any) error {
	return fmt.Errorf("hap: wrong response: %#v, on request: %#v", res, req)
}

View on GitHub (pinned to c245815e75)