{"record":{"id":"99ae3117257b1fc1","repo":"pion/webrtc","slug":"stream-is-nil-99ae31","errorCode":null,"errorMessage":"stream is nil","messagePattern":"stream is nil","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/media/h265reader/h265reader.go","lineNumber":25,"sourceCode":"import (\n\t\"bytes\"\n\t\"errors\"\n\t\"io\"\n)\n\n// H265Reader reads data from stream and constructs h265 nal units.\ntype H265Reader struct {\n\tstream                      io.Reader\n\tnalBuffer                   []byte\n\tcountOfConsecutiveZeroBytes int\n\tnalPrefixParsed             bool\n\treadBuffer                  []byte\n\ttmpReadBuf                  []byte\n\tincludeSEI                  bool\n}\n\nvar (\n\terrNilReader           = errors.New(\"stream is nil\")\n\terrDataIsNotH265Stream = errors.New(\"data is not a H265/HEVC bitstream\")\n)\n\nfunc (reader *H265Reader) shouldSkipNAL(naluType NalUnitType) bool {\n\treturn !reader.includeSEI && (naluType == NalUnitTypePrefixSei || naluType == NalUnitTypeSuffixSei)\n}\n\n// NewReader creates new H265Reader.\nfunc NewReader(in io.Reader) (*H265Reader, error) {\n\tif in == nil {\n\t\treturn nil, errNilReader\n\t}\n\n\treader := &H265Reader{\n\t\tstream:          in,\n\t\tnalBuffer:       make([]byte, 0),\n\t\tnalPrefixParsed: false,\n\t\treadBuffer:      make([]byte, 0),","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/pion/webrtc/blob/8c25dc09fa9e7c09aac4309ead88093d760432b0/pkg/media/h265reader/h265reader.go#L7-L43","documentation":"This error is returned by h265reader.NewReader when the io.Reader argument is nil. H265Reader needs an underlying stream to parse an H265/HEVC Annex-B bitstream; a nil reader cannot be used. It is the HEVC counterpart of errNilReader in h264reader.","triggerScenarios":"Calling h265reader.NewReader(nil), usually because the stream variable was never initialized or an upstream opener failed without being checked.","commonSituations":"Unchecked errors from os.Open or a network dial resulting in a nil reader; refactoring that removed stream initialization; conditionally-created sources that end up nil.","solutions":["Ensure the io.Reader is non-nil before calling NewReader; check errors from the code that creates it.","Match on errors.Is(err, <h265reader nil sentinel>) to produce a clearer message.","Fail fast with a contextual error at the call site."],"exampleFix":"// before\nrdr, err := h265reader.NewReader(stream) // stream may be nil\n// after\nif stream == nil {\n    return nil, errors.New(\"HEVC input stream is nil\")\n}\nrdr, err := h265reader.NewReader(stream)","handlingStrategy":"validation","validationCode":"if stream == nil {\n    return errors.New(\"h265 input stream is nil\")\n}\nrdr, err := h265reader.NewReader(stream)","typeGuard":"func hasReader(r io.Reader) bool { return r != nil }","tryCatchPattern":"rdr, err := h265reader.NewReader(stream)\nif err != nil {\n    return fmt.Errorf(\"h265reader init: %w\", err)\n}","preventionTips":["Check upstream open/creation errors before constructing the reader.","Keep stream initialization and reader construction in the same error-checked path.","Fail fast with contextual errors instead of passing nil downward."],"tags":["go","media","h265","hevc","nil-argument"],"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"}