{"record":{"id":"31767e7375e78fab","repo":"AlexxIT/go2rtc","slug":"api-streamnotfound","errorCode":null,"errorMessage":"api.StreamNotFound","messagePattern":"api\\.StreamNotFound","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/hls/ws.go","lineNumber":16,"sourceCode":"package hls\n\nimport (\n\t\"errors\"\n\t\"time\"\n\n\t\"github.com/AlexxIT/go2rtc/internal/api\"\n\t\"github.com/AlexxIT/go2rtc/internal/api/ws\"\n\t\"github.com/AlexxIT/go2rtc/internal/streams\"\n\t\"github.com/AlexxIT/go2rtc/pkg/mp4\"\n)\n\nfunc handlerWSHLS(tr *ws.Transport, msg *ws.Message) error {\n\tstream, _ := streams.GetOrPatch(tr.Request.URL.Query())\n\tif stream == nil {\n\t\treturn errors.New(api.StreamNotFound)\n\t}\n\n\tcodecs := msg.String()\n\tmedias := mp4.ParseCodecs(codecs, true)\n\tcons := mp4.NewConsumer(medias)\n\tcons.FormatName = \"hls/fmp4\"\n\tcons.WithRequest(tr.Request)\n\n\tlog.Trace().Msgf(\"[hls] new ws consumer codecs=%s\", codecs)\n\n\tif err := stream.AddConsumer(cons); err != nil {\n\t\tlog.Error().Err(err).Caller().Send()\n\t\treturn err\n\t}\n\n\tsession := NewSession(cons)\n\n\tsession.alive = time.AfterFunc(keepalive, func() {","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/AlexxIT/go2rtc/blob/c245815e75e2a5fd60b4290f12bfc04e55a984d3/internal/hls/ws.go#L1-L34","documentation":"The HLS-over-WebSocket handler looks up the stream named in the request query via streams.GetOrPatch. If no stream with that name exists (or the name is empty), it returns the shared api.StreamNotFound sentinel error, so the WS client knows the requested stream is unavailable.","triggerScenarios":"Opening the HLS WebSocket endpoint (/api/ws?src=NAME) with a src that doesn't match any configured stream name; stream removed/reloaded between page load and WS connect; case/typo mismatch in src.","commonSituations":"Front-end built for a different stream name; config reloaded removing the stream; URL-encoding issues mangling the src parameter.","solutions":["Verify the stream name in the query matches a stream key in the config exactly","List configured streams via GET /api/streams and correct the src parameter","If the stream was removed, restore it in config and reload"],"exampleFix":"// before\nnew WebSocket('ws://host:1984/api/ws?src=cam_1')\n// after\nnew WebSocket('ws://host:1984/api/ws?src=cam1')  // matches streams: cam1: ...","handlingStrategy":"validation","validationCode":"const src = new URLSearchParams({src: 'cam1'})\nconst streams = await (await fetch('/api/streams')).json()\nif (!(src.get('src') in streams)) throw new Error('stream not configured')","typeGuard":null,"tryCatchPattern":"ws.onerror = async () => { const streams = await (await fetch('/api/streams')).json(); if (!(name in streams)) showAlert('stream not found') }","preventionTips":["Fetch /api/streams before opening the HLS WS and validate src exists","Keep stream names in sync between frontend and config (single source of names)","Reconnect logic should re-validate the stream name after config reloads"],"tags":["hls","websocket","stream-not-found","go2rtc"],"backgroundTag":"resource-not-found","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"}