{"record":{"id":"440be1c85703dbcc","repo":"AlexxIT/go2rtc","slug":"add-track-from-none-state","errorCode":null,"errorMessage":"add track from none state","messagePattern":"add track from none state","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/streams/producer.go","lineNumber":118,"sourceCode":"\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tp.receivers = append(p.receivers, track)\n\n\tif p.state == stateMedias {\n\t\tp.state = stateTracks\n\t}\n\n\treturn track, nil\n}\n\nfunc (p *Producer) AddTrack(media *core.Media, codec *core.Codec, track *core.Receiver) error {\n\tp.mu.Lock()\n\tdefer p.mu.Unlock()\n\n\tif p.state == stateNone {\n\t\treturn errors.New(\"add track from none state\")\n\t}\n\n\tif err := p.conn.(core.Consumer).AddTrack(media, codec, track); err != nil {\n\t\treturn err\n\t}\n\n\tp.senders = append(p.senders, track)\n\n\tif p.state == stateMedias {\n\t\tp.state = stateTracks\n\t}\n\n\treturn nil\n}\n\nfunc (p *Producer) MarshalJSON() ([]byte, error) {\n\tif conn := p.conn; conn != nil {\n\t\treturn json.Marshal(conn)","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/AlexxIT/go2rtc/blob/c245815e75e2a5fd60b4290f12bfc04e55a984d3/internal/streams/producer.go#L100-L136","documentation":"Producer.AddTrack's state-machine guard: AddTrack was called while the producer is in stateNone, i.e. before its medias were probed. The producer refuses to attach a sender track because the connection is not yet in a state where tracks exist; like GetTrack, it requires at least stateMedias.","triggerScenarios":"Thrown at internal/streams/producer.go:118 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Probe the producer's medias first (Start / GetMedias) before AddTrack","Sequence consumer setup after the producer is ready rather than in parallel","Guard with state checks or waiters in custom pipelines"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}