aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-resource/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/fparkan-resource/src/lib.rs')
-rw-r--r--crates/fparkan-resource/src/lib.rs47
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");