AlexxIT/go2rtc · error

hap: wrong response: %#v, on request: %#v

Error message

hap: wrong response: %#v, on request: %#v

What it means

newResponseError reports that a HAP control response did not match what was expected for the given request. Dial, Pair and DeletePairing use it when decoding a response whose structure or result fields are invalid. Both the response and the original request are dumped with %#v for diagnosis.

Solutions

  1. Inspect the dumped request/response to see which field the device returned instead of the expected one.
  2. Confirm the accessory supports HAP pairing and is on the expected firmware/version.
  3. Delete stale pairings on the accessory and re-pair from scratch.
  4. Ensure the connection targets the accessory's HAP port (default 51826/TCP or advertised port), not another service.

Example fix

// before
conn, err := hap.Dial(accessoryAddr) // points at camera RTSP port 8554
// after
conn, err := hap.Dial("192.168.1.42:51826") // actual HAP port
Defensive patterns

Strategy: retry

Validate before calling

// verify host:port is the accessory HAP port before dialing
conn, err := net.DialTimeout("tcp", addr, 3*time.Second)

Try / catch

conn, err := hap.Dial(addr)
if err != nil {
    if strings.Contains(err.Error(), "wrong response") {
        // unpublish + re-pair
    }
    return err
}

Prevention

When it happens

Trigger: Calling hap Dial/Pair/DeletePairing against an accessory whose reply body fails to decode into the expected response type, or whose TLV indicates an error/unsupported state.

Common situations: Targeting a non-HAP or wrong-version device (e.g. HAP 1.x quirks); the accessory rejected the pairing method and returned an error TLV; network proxy rewriting the response 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/018e6564a5fd2ece. Report an issue: GitHub.

Appendix: source

Thrown at pkg/hap/helpers.go:129

	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)