pion/webrtc · error
%w: invalid comment %d
Error message
%w: invalid comment %d
What it means
Returned by parseSingleUserComment when a comment string, though fully present in the payload, contains no '=' separator. Per the Opus spec, every user comment must be a 'NAME=value' pair, so a comment without '=' is structurally invalid.
Source
Thrown at pkg/media/oggreader/oggreader.go:482
func parseSingleUserComment(payload []byte, pos, u32Size, index int) (UserComment, int, error) {
if pos+u32Size > len(payload) {
return UserComment{}, 0, fmt.Errorf("%w: payload too short for comment len %d", errBadOpusTagsSignature, index)
}
commentLen32 := binary.LittleEndian.Uint32(payload[pos : pos+u32Size])
pos += u32Size
commentLen := int(commentLen32)
if commentLen < 0 || pos+commentLen > len(payload) {
return UserComment{}, 0, fmt.Errorf("%w: payload too short for comment %d", errBadOpusTagsSignature, index)
}
comment := string(payload[pos : pos+commentLen])
pos += commentLen
parts := strings.SplitN(comment, "=", 2)
if len(parts) != 2 {
return UserComment{}, 0, fmt.Errorf("%w: invalid comment %d", errBadOpusTagsSignature, index)
}
return UserComment{
Comment: parts[0],
Value: parts[1],
}, pos, nil
}
View on GitHub (pinned to 8c25dc09fa)
Solutions
- Fix the metadata with a conforming tag editor (e.g. opustags, ffmpeg -metadata) ensuring every comment is NAME=value.
- Inspect the raw comments in the file to find the offending entry and correct or remove it.
- Use errors.Is(err, errBadOpusTagsSignature) to detect this and either reject the file or strip invalid comments.
- If you generate OpusTags yourself, always validate each comment contains '=' before serializing.
Example fix
// before: writing a bare comment
comments := []string{"TITLE Song"}
// after: ensure KEY=value form
comments := []string{"TITLE=Song"}
for _, c := range comments { if !strings.Contains(c, "=") { return errors.New("invalid comment") } } Defensive patterns
Strategy: try-catch
Validate before calling
func allCommentsAreKeyValue(rawComments []string) bool {
for _, c := range rawComments {
if !strings.Contains(c, "=") { return false }
}
return true
} Try / catch
tags, err := ParseOpusTags(payload)
if err != nil {
if errors.Is(err, errBadOpusTagsSignature) && strings.Contains(err.Error(), "invalid comment") {
return nil, fmt.Errorf("non-conforming metadata (comment missing '='): %w", err)
}
return nil, err
} Prevention
- Write metadata only with spec-conforming tools; every comment must be NAME=value.
- Validate comments contain '=' before serializing OpusTags yourself.
- When reading third-party files, run a pre-scan with opustags or ffprobe to catch bad taggers.
- Keep the '=' out of neither side: note the value side may contain '=' — only split on the first occurrence.
When it happens
Trigger: Parsing an OpusTags payload where comment N is a non-empty string lacking an '=' character (e.g. 'TITLE' instead of 'TITLE=Song'), so strings.SplitN(comment, "=", 2) yields only one part.
Common situations: Metadata written by broken or non-conforming taggers, hand-edited OpusTags blocks, tools that append bare strings as comments, or comments that were truncated exactly at (or before) the '=' sign by a prior corruption.
Related errors
- %w: user comment is too long
- %w: %s is too long
- bad opus tags signature
- %w: ambisonics family type 3 is not supported
- %w: payload too short
AI-assisted analysis of pion/webrtc@8c25dc09fa (2026-09-03).
Data as JSON: /api/errors/71b5a60121d51b45.
Report an issue: GitHub.