You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Include frame ID in text decoding error messages #639
When an ID3v2 text frame contains malformed UTF-16 content (e.g. odd byte length), lofty surfaces an error like: Text decoding: UTF-16 string has an odd length
I'm not very familiar with Rust, but I think the frame ID is available in parse_frame (in src/id3/v2/frame/read.rs) when parse_content fails, but is dropped by the ? operator:
fn parse_frame<R: Read>(
reader: &mut R,
size: u32,
id: FrameId<'static>,
...
) -> Result<ParsedFrame<'static>> {
match parse_content(reader, id, flags, version, parse_mode)? { // id lost on error
The fix might be something like adding context to the error before propagating:
Text decoding: UTF-16 string has an odd length (in frame 'TIT2')
..which makes it much easier for applications and end users to identify and fix the problematic tag without having to reimplement raw ID3 byte scanning themselves.
Yeah, there's lots of room for improvement in Lofty's errors. Especially in TextDecode, TooMuchData, SizeMismatch, and BadAtom.
When I get some time I'll look into refactoring Error to hold a chain of errors instead, so you could get a FrameParse error that wraps a child TextDecode error.
That'd make messages like this possible:
Failed to parse 'TIT2' frame
Caused by: UTF-16 string has an odd length
So far only Id3v2Tag, Id3v1Tag, and MpegFile parsing have full error traces. It's a huge refactor, so it'll probably be awhile before I can get it out.
You can now get nice error messages like:
failed to parse Mpeg file
Caused by: failed to parse ID3v2 tag
Caused by: failed to parse frame 'TPE1'
Caused by: failed to decode UTF-16 sequence: UTF-16 string has an invalid byte order mark
Activity
Serial-ATA commentedon Apr 4, 2026
Yeah, there's lots of room for improvement in Lofty's errors. Especially in
TextDecode,TooMuchData,SizeMismatch, andBadAtom.When I get some time I'll look into refactoring
Errorto hold a chain of errors instead, so you could get aFrameParseerror that wraps a childTextDecodeerror.That'd make messages like this possible:
Serial-ATA commentedon Apr 19, 2026
@NebuPookins I've been experimenting with retaining error sources on the
errorsbranch: https://github.com/Serial-ATA/lofty-rs/tree/errorsSo far only
Id3v2Tag,Id3v1Tag, andMpegFileparsing have full error traces. It's a huge refactor, so it'll probably be awhile before I can get it out.You can now get nice error messages like:
With a basic reporter like this: