{"record":{"id":"afc83cf763e1988e","repo":"pion/webrtc","slug":"stream-is-nil-afc83c","errorCode":null,"errorMessage":"stream is nil","messagePattern":"stream is nil","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/media/oggreader/oggreader.go","lineNumber":24,"sourceCode":"\nimport (\n\t\"encoding/binary\"\n\t\"errors\"\n\t\"fmt\"\n\t\"io\"\n\t\"strings\"\n)\n\nconst (\n\tpageHeaderTypeBeginningOfStream = 0x02\n\tpageHeaderSignature             = \"OggS\"\n\n\tidPageBasePayloadLength = 19\n\tpageHeaderLen           = 27\n)\n\nvar (\n\terrNilStream                       = errors.New(\"stream is nil\")\n\terrBadIDPageSignature              = errors.New(\"bad header signature\")\n\terrBadOpusTagsSignature            = errors.New(\"bad opus tags signature\")\n\terrBadIDPageType                   = errors.New(\"wrong header, expected beginning of stream\")\n\terrBadIDPageLength                 = errors.New(\"payload for id page must be 19 bytes\")\n\terrBadIDPagePayloadSignature       = errors.New(\"bad payload signature\")\n\terrShortPageHeader                 = errors.New(\"not enough data for payload header\")\n\terrChecksumMismatch                = errors.New(\"expected and actual checksum do not match\")\n\terrUnsupportedChannelMappingFamily = errors.New(\"unsupported channel mapping family\")\n)\n\n// OggReader is used to read Ogg files and return page payloads.\ntype OggReader struct {\n\tstream               io.Reader\n\tbytesReadSuccesfully int64\n\tchecksumTable        *[256]uint32\n\tdoChecksum           bool\n}\n","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/pion/webrtc/blob/8c25dc09fa9e7c09aac4309ead88093d760432b0/pkg/media/oggreader/oggreader.go#L6-L42","documentation":"errNilStream is returned by oggreader's NewWith (and similarly ivfreader.NewWith) when the io.Reader passed in is a nil interface. The library cannot read from a nil stream, so it fails fast instead of panicking on the first Read. This is purely a caller-side setup mistake.","triggerScenarios":"Calling oggreader.NewWith(nil) or passing a typed-nil reader (e.g. var r *bytes.Reader; NewWith(r) where r is nil), typically when a variable failed to initialize earlier.","commonSituations":"Functions that return (io.Reader, error) where the error path returns nil but the caller ignores the error; deferred initialization of a file handle; refactors where a reader field was never assigned.","solutions":["Ensure a non-nil io.Reader is constructed before calling NewWith","Check the error from whatever produces the reader instead of passing its nil result through","Use os.Open / bytes.NewReader explicitly and verify non-nil","In code paths, guard `if r == nil` before handing the reader to the library"],"exampleFix":"// before\nvar r io.Reader\nogg, err := oggreader.NewWith(r) // errNilStream\n// after\nf, err := os.Open(\"audio.ogg\")\nif err != nil { return err }\nogg, err := oggreader.NewWith(f)","handlingStrategy":"validation","validationCode":"if stream == nil {\n    return errors.New(\"oggreader: input stream must be non-nil\")\n}\nogg, _, err := oggreader.NewWith(stream)","typeGuard":"func isNonNilReader(r io.Reader) bool { return r != nil }","tryCatchPattern":"ogg, _, err := oggreader.NewWith(stream)\nif err != nil {\n    return fmt.Errorf(\"failed to init ogg reader: %w\", err)\n}","preventionTips":["Never pass the result of a failed constructor call straight into NewWith","Check `if r == nil` at API boundaries","Avoid typed-nil pointers assigned to io.Reader variables","Initialize readers close to where they are used"],"tags":["go","media","ogg","nil-pointer"],"backgroundTag":"nil-reader-argument","analyzedSha":"8c25dc09fa9e7c09aac4309ead88093d760432b0","analyzedAt":"2026-09-03T21:56:56.182Z","contentChangedAt":"2026-09-03T21:56:56.182Z","schemaVersion":2},"datasetVersion":"2026-09-11T07:07:21.782Z"}