Skip to content

The great error refactor - #669

Merged
Serial-ATA merged 22 commits into
mainfrom
errors
Jun 25, 2026
Merged

Serial-ATA merged 22 commits into
mainfrom
errors

Conversation

@Serial-ATA

Copy link
Copy Markdown
Owner

This removes LoftyError and replaces it with new FileParseError and FileEncodingError types that track their sources. This means you can finally tell why and where something failed.

For example, invalid UTF-16 in an ID3v2 frame would previously report:

UTF-16 string has an invalid byte order mark

But now you can get much richer error traces:

failed to parse Mpeg file
Caused by: failed to parse Id3v2 tag
Caused by: failed to parse frame 'TIT2'
Caused by: failed to decode UTF-16 sequence: UTF-16 string has an invalid byte order mark

With a basic error reporter like so:

fn report(mut err: &(dyn std::error::Error + 'static)) -> String {
	use std::fmt::Write;
	let mut s = format!("{err}");
	while let Some(src) = err.source() {
		let _ = write!(s, "\nCaused by: {src}");
		err = src;
	}
	s
}

match Probe::open(path).and_then(Probe::read) {
	Ok(_) => {
		println!("Parsed file successfully!");
	},
	Err(e) => {
		eprintln!("{}", report(&e));
	},
};

closes #639

@Serial-ATA Serial-ATA added this to the 0.25.0 milestone Jun 23, 2026
@Serial-ATA
Serial-ATA merged commit 2112dd9 into main Jun 25, 2026
5 checks passed
@Serial-ATA
Serial-ATA deleted the errors branch June 25, 2026 00:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Include frame ID in text decoding error messages

1 participant