{"record":{"id":"6bafad2844f6ec49","repo":"pion/webrtc","slug":"w-expected-q-got-q","errorCode":null,"errorMessage":"%w: expected %q, got %q","messagePattern":"%w: expected %q, got %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/media/oggreader/oggreader.go","lineNumber":418,"sourceCode":"\tuserComments, err := parseUserComments(payload, vendorEnd, u32Size)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn &OpusTags{\n\t\tVendor:       vendor,\n\t\tUserComments: userComments,\n\t}, nil\n}\n\nfunc validateOpusTagsHeader(payload []byte, minHeaderLen int) error {\n\tif len(payload) < minHeaderLen {\n\t\treturn fmt.Errorf(\"%w: payload too short\", errBadOpusTagsSignature)\n\t}\n\n\tgot := HeaderType(payload[:8])\n\tif got != HeaderOpusTags {\n\t\treturn fmt.Errorf(\"%w: expected %q, got %q\", errBadOpusTagsSignature, HeaderOpusTags, got)\n\t}\n\n\treturn nil\n}\n\nfunc parseVendorString(payload []byte, headerMagicLen, u32Size, minHeaderLen int) (string, int, error) {\n\tvendorLen32 := binary.LittleEndian.Uint32(payload[headerMagicLen : headerMagicLen+u32Size])\n\tif int(vendorLen32) > len(payload)-minHeaderLen {\n\t\treturn \"\", 0, fmt.Errorf(\"%w: payload too short for vendor string\", errBadOpusTagsSignature)\n\t}\n\tvendorLen := int(vendorLen32)\n\n\tvendorStart := headerMagicLen + u32Size\n\tvendorEnd := vendorStart + vendorLen\n\tif vendorEnd+u32Size > len(payload) {\n\t\treturn \"\", 0, fmt.Errorf(\"%w: payload too short for vendor+comment count\", errBadOpusTagsSignature)\n\t}\n","sourceCodeStart":400,"sourceCodeEnd":436,"githubUrl":"https://github.com/pion/webrtc/blob/8c25dc09fa9e7c09aac4309ead88093d760432b0/pkg/media/oggreader/oggreader.go#L400-L436","documentation":"validateOpusTagsHeader rejects a payload whose first 8 bytes are not the 'OpusTags' magic string. ParseOpusTags only parses Opus comment headers, so any other header type (e.g. 'OpusHead') or garbage bytes trigger this wrapped errBadOpusTagsSignature error, reporting expected vs received magic.","triggerScenarios":"Calling ParseOpusTags on the OpusHead (identification) packet, on an audio data packet, or on any non-comment-header packet; byte offsets misaligned so payload[:8] is not the magic.","commonSituations":"Iterating an Ogg stream and feeding every packet to ParseOpusTags instead of only the second logical-stream packet; stream starts mid-file so the ID header was missed and packets are misidentified; corrupted first 8 bytes of the tags packet.","solutions":["Identify the correct packet: check bytes.HasPrefix(payload, []byte(\"OpusTags\")) before calling ParseOpusTags and route 'OpusHead' packets to ParseOpusHead instead.","Re-scan the stream to locate the actual OpusTags packet (usually the second packet of the first logical stream).","Handle errors.Is(err, ErrBadOpusTagsSignature) at the call site and skip non-tags packets rather than aborting."],"exampleFix":"// before\ntags, err := oggreader.ParseOpusTags(packet) // may be OpusHead packet\n// after\nif bytes.HasPrefix(packet, []byte(\"OpusTags\")) {\n    tags, err = oggreader.ParseOpusTags(packet)\n}","handlingStrategy":"type-guard","validationCode":"if bytes.HasPrefix(payload, []byte(\"OpusTags\")) {\n    tags, err := oggreader.ParseOpusTags(payload)\n} else if bytes.HasPrefix(payload, []byte(\"OpusHead\")) {\n    head, err := oggreader.ParseOpusHead(payload)\n}","typeGuard":"func isOpusTagsPacket(p []byte) bool {\n    return len(p) >= 8 && string(p[:8]) == \"OpusTags\"\n}","tryCatchPattern":"tags, err := oggreader.ParseOpusTags(payload)\nvar sigErr *? // sentinel-based check:\nif errors.Is(err, oggreader.ErrBadOpusTagsSignature) {\n    // wrong packet type: route to ParseOpusHead or skip\n}","preventionTips":["Track packet index per logical stream: parse tags only for the OpusTags (usually second) packet.","Dispatch on the 8-byte magic before calling any parser.","Handle streams starting mid-file by scanning forward for the OpusTags magic.","Log the received HeaderType from the error message to diagnose misrouted packets."],"tags":["go","ogg","opus","invalid-magic","wrong-packet"],"backgroundTag":"invalid-header-signature","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"}