{"record":{"id":"921bae4891f7ae57","repo":"AlexxIT/go2rtc","slug":"streams-source-empty","errorCode":null,"errorMessage":"streams: source empty","messagePattern":"streams: source empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/streams/streams.go","lineNumber":122,"sourceCode":"\t}\n\n\t// check an existing stream with this name\n\tif stream, ok := streams[name]; ok {\n\t\tstream.SetSource(source)\n\t\treturn stream, nil\n\t}\n\n\t// create new stream with this name\n\tstream := NewStream(source)\n\tstreams[name] = stream\n\treturn stream, nil\n}\n\nfunc GetOrPatch(query url.Values) (*Stream, error) {\n\t// check if src param exists\n\tsource := query.Get(\"src\")\n\tif source == \"\" {\n\t\treturn nil, errors.New(\"streams: source empty\")\n\t}\n\n\t// check if src is stream name\n\tif stream := Get(source); stream != nil {\n\t\treturn stream, nil\n\t}\n\n\t// check if name param provided\n\tif name := query.Get(\"name\"); name != \"\" {\n\t\treturn Patch(name, source)\n\t}\n\n\t// return new stream with src as name\n\treturn Patch(source, source)\n}\n\nvar log zerolog.Logger\n","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/AlexxIT/go2rtc/blob/c245815e75e2a5fd60b4290f12bfc04e55a984d3/internal/streams/streams.go#L104-L140","documentation":"GetOrPatch reads the `src` query parameter to locate or create a stream; when the parameter is absent or empty the request is meaningless, so the API handlers (WSHLS, MP4, WS, MSE, keyframe endpoints) return this error.","triggerScenarios":"Calling any stream consumer endpoint (e.g. /api/ws, /api/stream.mp4, /api/stream.m3u8) without `?src=...`, or with `src=` empty; programmatically calling streams.GetOrPatch(url.Values{}) with no src key.","commonSituations":"Embedded player code built with the stream name omitted; HTML templates that interpolate an empty src variable; frontend URL built after stream name fetch failed silently.","solutions":["Add or fix the src query parameter in the request URL, e.g. /api/ws?src=camera1","Verify the variable holding the stream name in the client/template isn't empty at request time","When calling GetOrPatch directly, validate that query.Get(\"src\") != \"\" before calling"],"exampleFix":"// before\nconst ws = new WebSocket(`ws://host/api/ws?src=${name}`); // name === \"\"\n// after\nif (!name) throw new Error(\"stream name required\");\nconst ws = new WebSocket(`ws://host/api/ws?src=${encodeURIComponent(name)}`);","handlingStrategy":"validation","validationCode":"if query.Get(\"src\") == \"\" {\n\treturn errors.New(\"src query parameter is required\")\n}\nstream, err := streams.GetOrPatch(query)","typeGuard":null,"tryCatchPattern":"stream, err := streams.GetOrPatch(query)\nif err != nil {\n\thttp.Error(w, \"missing 'src' query parameter\", http.StatusBadRequest)\n\treturn\n}","preventionTips":["Always build stream consumer URLs with the src parameter","Use URL templates in player code with required src validation","Return HTTP 400 with a clear message in custom handlers when src is missing"],"tags":["go","api","query-parameters"],"backgroundTag":"missing-required-argument","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"}