AlexxIT/go2rtc · error

api.StreamNotFound

Error message

api.StreamNotFound

What it means

apiUnpair removes a HomeKit pairing bound to a go2rtc stream. It first fetches the stream by id via streams.Get; if no stream with that id exists it returns the shared api.StreamNotFound sentinel error, because there is nothing to unpair.

Solutions

  1. Check the stream id via GET /api/streams and unpair with an existing id
  2. Restore the stream in the config if it was removed unintentionally
  3. Treat StreamNotFound as already-unpaired in automation and ignore it

Example fix

// before
await fetch('/api/homekit/unpair?id=old_cam')
// after
await fetch('/api/homekit/unpair?id=cam1')  // id that exists in streams
Defensive patterns

Strategy: validation

Validate before calling

const streams = await (await fetch('/api/streams')).json()
if (!(id in streams)) return // already unpaired or wrong id
await fetch('/api/homekit/unpair?id=' + id)

Try / catch

const res = await fetch('/api/homekit/unpair?id='+id); if (res.status !== 200) { /* id may not exist; treat as already unpaired */ }

Prevention

When it happens

Trigger: DELETE/POST to the HomeKit unpair API with an id that doesn't match any configured stream; stream deleted before unpair; id case/typo mismatch.

Common situations: Stale HomeKit accessory cache referencing deleted streams; renaming a stream then unpairing by the old name; automation calling unpair twice (second call hits it).

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


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

Appendix: source

Thrown at internal/homekit/api.go:154

	return sources, nil
}

func apiPair(id, url string) error {
	conn, err := hap.Pair(url)
	if err != nil {
		return err
	}

	streams.New(id, conn.URL())

	return app.PatchConfig([]string{"streams", id}, conn.URL())
}

func apiUnpair(id string) error {
	stream := streams.Get(id)
	if stream == nil {
		return errors.New(api.StreamNotFound)
	}

	rawURL := findHomeKitURL(stream.Sources())
	if rawURL == "" {
		return errors.New("not homekit source")
	}

	if err := hap.Unpair(rawURL); err != nil {
		return err
	}

	streams.Delete(id)

	return app.PatchConfig([]string{"streams", id}, nil)
}

func findHomeKitURLs() map[string]*url.URL {
	urls := map[string]*url.URL{}

View on GitHub (pinned to c245815e75)