{"record":{"id":"74805ae72a8ad1dd","repo":"pion/webrtc","slug":"output-not-opened","errorCode":null,"errorMessage":"output not opened","messagePattern":"output not opened","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/media/oggwriter/oggwriter.go","lineNumber":49,"sourceCode":"\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 {\n\tsampleRate     uint32","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/pion/webrtc/blob/8c25dc09fa9e7c09aac4309ead88093d760432b0/pkg/media/oggwriter/oggwriter.go#L31-L67","documentation":"errOutputNotOpened is returned by oggwriter.NewWriter when the provided io.Writer is nil, and by the internal stream-access path when w.stream is nil (e.g. writing before a valid output was attached). It indicates the writer has no destination to serialize Ogg pages into.","triggerScenarios":"NewWriter(nil) (oggwriter.go:391); internal write path encountering w.stream == nil (oggwriter.go:432); asserted by TestOggWriter_NewWriterRequiresOutput.","commonSituations":"Ignoring the error from os.Create so a nil file reaches NewWriter, constructing a Writer via a struct literal without setting stream, closing the file and continuing to write.","solutions":["Create/open the destination and check its error before NewWriter","Never construct Writer directly without a stream; use NewWriter","Verify the file is not closed/nil before each WriteRTP/Close sequence"],"exampleFix":"// before\nf, _ := os.Create(\"out.ogg\")\nw, err := oggwriter.NewWriter(f) // errOutputNotOpened if f nil\n// after\nf, err := os.Create(\"out.ogg\")\nif err != nil {\n    return err\n}\nw, err := oggwriter.NewWriter(f)","handlingStrategy":"validation","validationCode":"if out == nil {\n    return errors.New(\"ogg writer requires a non-nil io.Writer\")\n}\nw, err := oggwriter.NewWriter(out)","typeGuard":"func hasOutputStream(w *oggwriter.Writer) bool {\n    return w != nil\n}","tryCatchPattern":"w, err := oggwriter.NewWriter(out)\nif errors.Is(err, oggwriter.ErrOutputNotOpened) {\n    return fmt.Errorf(\"ogg output missing: %w\", err)\n}","preventionTips":["Construct writers only via NewWriter with a checked, open destination","Do not close the underlying file before writer.Close()","Avoid zero-value Writer structs; always use the constructor"],"tags":["ogg","writer","nil-argument","io"],"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"}