pion/webrtc · error
stream is nil
Error message
stream is nil
What it means
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.
Source
Thrown at pkg/media/h265reader/h265reader.go:25
import (
"bytes"
"errors"
"io"
)
// H265Reader reads data from stream and constructs h265 nal units.
type H265Reader struct {
stream io.Reader
nalBuffer []byte
countOfConsecutiveZeroBytes int
nalPrefixParsed bool
readBuffer []byte
tmpReadBuf []byte
includeSEI bool
}
var (
errNilReader = errors.New("stream is nil")
errDataIsNotH265Stream = errors.New("data is not a H265/HEVC bitstream")
)
func (reader *H265Reader) shouldSkipNAL(naluType NalUnitType) bool {
return !reader.includeSEI && (naluType == NalUnitTypePrefixSei || naluType == NalUnitTypeSuffixSei)
}
// NewReader creates new H265Reader.
func NewReader(in io.Reader) (*H265Reader, error) {
if in == nil {
return nil, errNilReader
}
reader := &H265Reader{
stream: in,
nalBuffer: make([]byte, 0),
nalPrefixParsed: false,
readBuffer: make([]byte, 0),View on GitHub (pinned to 8c25dc09fa)
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.
Example fix
// before
rdr, err := h265reader.NewReader(stream) // stream may be nil
// after
if stream == nil {
return nil, errors.New("HEVC input stream is nil")
}
rdr, err := h265reader.NewReader(stream) Defensive patterns
Strategy: validation
Validate before calling
if stream == nil {
return errors.New("h265 input stream is nil")
}
rdr, err := h265reader.NewReader(stream) Type guard
func hasReader(r io.Reader) bool { return r != nil } Try / catch
rdr, err := h265reader.NewReader(stream)
if err != nil {
return fmt.Errorf("h265reader init: %w", err)
} Prevention
- 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.
When it happens
Trigger: Calling h265reader.NewReader(nil), usually because the stream variable was never initialized or an upstream opener failed without being checked.
Common situations: 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.
Related errors
- data is not a H265/HEVC bitstream
- stream is nil
- stream is nil
- data is not a H264 bitstream
- incomplete frame header
AI-assisted analysis of pion/webrtc@8c25dc09fa (2026-09-03).
Data as JSON: /api/errors/99ae3117257b1fc1.
Report an issue: GitHub.