{"record":{"id":"13a4cf03a982855f","repo":"AlexxIT/go2rtc","slug":"api-streamnotfound-13a4cf","errorCode":null,"errorMessage":"api.StreamNotFound","messagePattern":"api\\.StreamNotFound","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/mjpeg/mjpeg.go","lineNumber":196,"sourceCode":"\t\treturn\n\t}\n\n\tprod, _ := mpjpeg.Open(r.Body)\n\tprod.WithRequest(r)\n\n\tstream.AddProducer(prod)\n\n\tif err := prod.Start(); err != nil && err != io.EOF {\n\t\tlog.Warn().Err(err).Caller().Send()\n\t}\n\n\tstream.RemoveProducer(prod)\n}\n\nfunc handlerWS(tr *ws.Transport, _ *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\tcons := mjpeg.NewConsumer()\n\tcons.WithRequest(tr.Request)\n\n\tif err := stream.AddConsumer(cons); err != nil {\n\t\tlog.Debug().Err(err).Msg(\"[mjpeg] add consumer\")\n\t\treturn err\n\t}\n\n\ttr.Write(&ws.Message{Type: \"mjpeg\"})\n\n\tgo cons.WriteTo(tr.Writer())\n\n\ttr.OnClose(func() {\n\t\tstream.RemoveConsumer(cons)\n\t})\n","sourceCodeStart":178,"sourceCodeEnd":214,"githubUrl":"https://github.com/AlexxIT/go2rtc/blob/c245815e75e2a5fd60b4290f12bfc04e55a984d3/internal/mjpeg/mjpeg.go#L178-L214","documentation":"The MJPEG WebSocket handler (handlerWS) looks up the stream named by the request's query parameters via streams.GetOrPatch. If no stream with that name exists (nil result), it returns the api.StreamNotFound error, refusing to create the MJPEG consumer.","triggerScenarios":"Opening a WS/MJPEG connection with a ?src=name query parameter that doesn't match any configured or dynamically created stream; empty or misspelled src parameter.","commonSituations":"Frontend JS pointing at a stream name that was renamed or removed from go2rtc.yaml, case-sensitive name mismatch, or forgetting the src query parameter entirely.","solutions":["Ensure the WS URL query includes src=<existing stream name> exactly as configured","Verify the stream exists in go2rtc.yaml or was created via the streams API before connecting","Check for typos and case differences in the stream name","Confirm go2rtc reloaded the config after adding the stream"],"exampleFix":"// before\nnew WebSocket(\"ws://host:1984/api/ws?src=camm\")\n// after\nnew WebSocket(\"ws://host:1984/api/ws?src=cam\")","handlingStrategy":"validation","validationCode":"// JS: verify the stream exists before opening WS/MJPEG\nconst res = await fetch(`http://host:1984/api/streams?src=${name}`)\nif (!(await res.ok)) throw new Error(`stream ${name} not found`)\nconst ws = new WebSocket(`ws://host:1984/api/ws?src=${name}`)","typeGuard":null,"tryCatchPattern":"// JS\nws.onerror = (e) => console.error('mjpeg ws failed — check src stream name:', e)\nws.onclose = (ev) => { if (ev.code === 1006) checkStreamExists() }","preventionTips":["Keep stream names in a shared constant/config between backend and frontend","Validate the src parameter against the /api/streams list before connecting","Handle stream renames centrally in the frontend"],"tags":["mjpeg","websocket","stream-not-found","api"],"backgroundTag":"stream-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"}