{"record":{"id":"ea042512fd75a92f","repo":"pion/webrtc","slug":"file-not-opened-ea0425","errorCode":null,"errorMessage":"file not opened","messagePattern":"file not opened","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/media/oggwriter/oggwriter.go","lineNumber":48,"sourceCode":"\topusGranuleSampleRate              = 48000\n\tmaxOpusPacketSamples               = opusGranuleSampleRate * 120 / 1000\n\tdefaultChannelCount                = 2\n\tchannelMappingFamily0              = 0\n\tchannelMappingFamily1              = 1\n\tchannelMappingFamily2              = 2\n\tchannelMappingFamily255            = 255\n\tidPageSignature                    = \"OpusHead\"\n\tcommentPageSignature               = \"OpusTags\"\n\tdefaultVendor                      = \"pion\"\n\tpageHeaderSignature                = \"OggS\"\n\tpageHeaderSize                     = 27\n\tmaxOggPageSegments                 = 255\n\tnoGranulePosition                  = ^uint64(0)\n\tmaxUint32Length                    = uint64(1<<32 - 1)\n)\n\nvar (\n\terrFileNotOpened        = errors.New(\"file not opened\")\n\terrOutputNotOpened      = errors.New(\"output not opened\")\n\terrInvalidNilPacket     = errors.New(\"invalid nil packet\")\n\terrDuplicateTrackSSRC   = errors.New(\"duplicate Ogg track SSRC\")\n\terrDuplicateTrackSerial = errors.New(\"duplicate Ogg track serial\")\n\terrTracksStarted        = errors.New(\"cannot add Ogg tracks after writing has started\")\n\terrPacketSSRCMismatch   = errors.New(\"RTP packet SSRC does not match Ogg track SSRC\")\n\terrInvalidOpusPacket    = errors.New(\"invalid Opus packet\")\n\terrInvalidChannelCount  = errors.New(\"invalid channel count\")\n\terrInvalidChannelMap    = errors.New(\"invalid channel mapping\")\n\terrInvalidOpusTags      = errors.New(\"invalid OpusTags\")\n)\n\ntype pageRewriter interface {\n\tio.Seeker\n\tio.WriterAt\n}\n\ntype writerConfig struct {","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/pion/webrtc/blob/8c25dc09fa9e7c09aac4309ead88093d760432b0/pkg/media/oggwriter/oggwriter.go#L30-L66","documentation":"errFileNotOpened is returned when a writer constructor or write call receives a nil output target. Despite the name, in this codebase it is shared with ivfwriter, where NewWith returns it when the io.Writer argument is nil. It guards against writing into a nil destination.","triggerScenarios":"Calling ivfwriter.NewWith(nil) (ivfwriter.go:84); oggwriter's NewWith path checks the output and returns errFileNotOpened analogously. Referenced in TestIVFWriter_Basic and TestOggWriter_AddPacketAndClose.","commonSituations":"An os.Create/os.Open error was ignored leaving a nil *os.File, a factory function returns nil writer on failure, refactoring removed the writer initialization.","solutions":["Check the error from os.Create/os.Open before passing the file","Pass a non-nil io.Writer (os.File, bytes.Buffer, etc.)","Guard with a nil check before constructing the writer"],"exampleFix":"// before\nf, _ := os.Create(\"out.ivf\")\nw, err := ivfwriter.NewWith(f) // errFileNotOpened if f is nil\n// after\nf, err := os.Create(\"out.ivf\")\nif err != nil {\n    return err\n}\nw, err := ivfwriter.NewWith(f)","handlingStrategy":"validation","validationCode":"if out == nil {\n    return errors.New(\"writer output is nil\")\n}\nw, err := ivfwriter.NewWith(out)","typeGuard":"func hasOutput(w io.Writer) bool { return w != nil }","tryCatchPattern":"w, err := ivfwriter.NewWith(out)\nif errors.Is(err, ivfwriter.ErrFileNotOpened) {\n    return fmt.Errorf(\"no output provided: %w\", err)\n}","preventionTips":["Always check the error from os.Create/os.Open before constructing a writer","Never pass a possibly-nil *os.File through helper functions unchecked","Return errors from factory functions instead of nil writers"],"tags":["io","writer","nil-argument","ogg","ivf"],"backgroundTag":"nil-output-writer","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"}