diff options
| author | Valentin Popov <valentin@popov.link> | 2026-06-22 15:41:21 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-06-22 15:41:21 +0300 |
| commit | 8b91a0bfbf0097d145359c8508a61696ade812d1 (patch) | |
| tree | 3e0f3c1c72034b13b73260fca204c101fc7aa379 /crates/fparkan-resource/src | |
| parent | fb97405e0c47dadf656e5c92c76ddaff95d78222 (diff) | |
| download | fparkan-8b91a0bfbf0097d145359c8508a61696ade812d1.tar.xz fparkan-8b91a0bfbf0097d145359c8508a61696ade812d1.zip | |
fix: make core error displays actionable
Diffstat (limited to 'crates/fparkan-resource/src')
| -rw-r--r-- | crates/fparkan-resource/src/lib.rs | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/crates/fparkan-resource/src/lib.rs b/crates/fparkan-resource/src/lib.rs index b09c946..b84f6f9 100644 --- a/crates/fparkan-resource/src/lib.rs +++ b/crates/fparkan-resource/src/lib.rs @@ -128,7 +128,30 @@ pub enum ResourceError { impl std::fmt::Display for ResourceError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{self:?}") + match self { + Self::MissingArchive => write!(f, "archive was not found"), + Self::MissingEntry => write!(f, "resource entry was not found in the archive"), + Self::InvalidHandle => write!( + f, + "resource handle does not reference an open archive entry" + ), + Self::StaleHandle => { + write!(f, "resource handle belongs to an older archive generation") + } + Self::Format(message) => write!(f, "resource archive format error: {message}"), + Self::EntryRead { key, source } => { + write!( + f, + "failed to read resource {}:{} from {}: {}", + key.type_id + .map_or_else(|| "-".to_string(), |type_id| type_id.to_string()), + String::from_utf8_lossy(&key.name.0), + key.archive.as_str(), + source + ) + } + Self::Poisoned => write!(f, "resource repository state lock was poisoned"), + } } } @@ -885,6 +908,28 @@ mod tests { } #[test] + fn resource_error_display_is_actionable() { + let path = archive_path(b"bad/rsli.lib").expect("path"); + let err = ResourceError::EntryRead { + key: ResourceKey { + archive: path, + name: resource_name(b"BROKEN.TEX"), + type_id: None, + }, + source: "unsupported packing method 0x1e0".to_string(), + }; + + assert_eq!( + err.to_string(), + "failed to read resource -:BROKEN.TEX from bad/rsli.lib: unsupported packing method 0x1e0" + ); + assert_eq!( + ResourceError::StaleHandle.to_string(), + "resource handle belongs to an older archive generation" + ); + } + + #[test] #[ignore = "requires licensed corpus"] fn licensed_corpora_repository_reads_nres_and_rsli() { licensed_repository_gate("IS").expect("part 1 repository gate"); |
