{"record":{"id":"c15bf64620a4b0b2","repo":"pion/webrtc","slug":"stream-is-nil-c15bf6","errorCode":null,"errorMessage":"stream is nil","messagePattern":"stream is nil","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/media/ivfreader/ivfreader.go","lineNumber":21,"sourceCode":"\n// Package ivfreader implements IVF media container reader\npackage ivfreader\n\nimport (\n\t\"encoding/binary\"\n\t\"errors\"\n\t\"fmt\"\n\t\"io\"\n)\n\nconst (\n\tivfFileHeaderSignature = \"DKIF\"\n\tivfFileHeaderSize      = 32\n\tivfFrameHeaderSize     = 12\n)\n\nvar (\n\terrNilStream             = errors.New(\"stream is nil\")\n\terrIncompleteFrameHeader = errors.New(\"incomplete frame header\")\n\terrIncompleteFrameData   = errors.New(\"incomplete frame data\")\n\terrIncompleteFileHeader  = errors.New(\"incomplete file header\")\n\terrSignatureMismatch     = errors.New(\"IVF signature mismatch\")\n\terrUnknownIVFVersion     = errors.New(\"IVF version unknown, parser may not parse correctly\")\n\terrInvalidMediaTimebase  = errors.New(\"invalid media timebase\")\n)\n\n// IVFFileHeader 32-byte header for IVF files\n// https://wiki.multimedia.cx/index.php/IVF\ntype IVFFileHeader struct {\n\tsignature           string // 0-3\n\tversion             uint16 // 4-5\n\theaderSize          uint16 // 6-7\n\tFourCC              string // 8-11\n\tWidth               uint16 // 12-13\n\tHeight              uint16 // 14-15\n\tTimebaseDenominator uint32 // 16-19","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/pion/webrtc/blob/8c25dc09fa9e7c09aac4309ead88093d760432b0/pkg/media/ivfreader/ivfreader.go#L3-L39","documentation":"Returned by ivfreader.NewWith (and internal newWith) when the io.Reader stream argument is nil. IVFReader reads IVF container frames from a stream; a nil stream cannot be read, so construction fails immediately with this sentinel error.","triggerScenarios":"Calling ivfreader.NewWith(nil), or New on a path where the internal stream is nil.","commonSituations":"os.Open failing and its error ignored so the file handle is nil; an optional IVF input missing in config; test code constructing readers with untyped nil.","solutions":["Check errors from the code that opens/creates the stream before calling NewWith.","Guard with `if stream == nil` and return a contextual error.","Use errors.Is(err, ivfreader.ErrNilStream-equivalent) when classifying the failure."],"exampleFix":"// before\nf, _ := os.Open(path)\nr, _, err := ivfreader.NewWith(f) // f may be nil\n// after\nf, err := os.Open(path)\nif err != nil {\n    return err\n}\nr, _, err := ivfreader.NewWith(f)","handlingStrategy":"validation","validationCode":"if stream == nil {\n    return errors.New(\"IVF input stream is nil\")\n}\nr, hdr, err := ivfreader.NewWith(stream)","typeGuard":"func hasStream(r io.Reader) bool { return r != nil }","tryCatchPattern":"r, hdr, err := ivfreader.NewWith(stream)\nif err != nil {\n    return fmt.Errorf(\"ivfreader init: %w\", err)\n}","preventionTips":["Always check the error from os.Open / network dial before NewWith.","Don't use a typed-nil (*os.File)(nil) as io.Reader; it passes a nil interface check differently.","Initialize streams in constructors that cannot silently return nil."],"tags":["go","media","ivf","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"}