From 9bc18cb1c4327fc68fb6fae6406ca01764581d38 Mon Sep 17 00:00:00 2001 From: Truman Kilen Date: Mon, 22 Apr 2024 20:48:05 -0500 Subject: [PATCH] Improve asset registry error handling --- src/integrate.rs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/integrate.rs b/src/integrate.rs index 3077e02f..a6ff5d5e 100644 --- a/src/integrate.rs +++ b/src/integrate.rs @@ -162,24 +162,33 @@ pub enum IntegrationError { RepakError { source: repak::Error }, #[snafu(transparent)] UnrealAssetError { source: unreal_asset::Error }, - #[snafu(display("mod {}: I/O error encountered during its processing", mod_info.name))] + #[snafu(display("mod {:?}: I/O error encountered during its processing", mod_info.name))] CtxtIoError { source: std::io::Error, mod_info: ModInfo, }, - #[snafu(display("mod {}: repak error encountered during its processing", mod_info.name))] + #[snafu(display("mod {:?}: repak error encountered during its processing", mod_info.name))] CtxtRepakError { source: repak::Error, mod_info: ModInfo, }, #[snafu(display( - "modfile {} of mod {mod_info:?} contains unexpected prefix", + "mod {:?}: modfile {} contains unexpected prefix", + mod_info.name, modfile_path ))] ModfileInvalidPrefix { mod_info: ModInfo, modfile_path: String, }, + #[snafu(display( + "mod {:?}: failed to integrate: {source}", + mod_info.name, + ))] + CtxtGenericError { + source: Box, + mod_info: ModInfo, + }, #[snafu(transparent)] ProviderError { source: ProviderError }, #[snafu(display("integration error: {msg}"))] @@ -199,6 +208,7 @@ impl IntegrationError { match self { IntegrationError::CtxtIoError { mod_info, .. } | IntegrationError::CtxtRepakError { mod_info, .. } + | IntegrationError::CtxtGenericError { mod_info, .. } | IntegrationError::ModfileInvalidPrefix { mod_info, .. } => mod_info.modio_id, IntegrationError::ProviderError { source } => source.opt_mod_id(), _ => None, @@ -382,7 +392,10 @@ pub fn integrate>( .build()?; asset_registry .populate(normalized.with_extension("").as_str(), &asset) - .map_err(|e| IntegrationError::GenericError { msg: e.to_string() })?; + .map_err(|e| IntegrationError::CtxtGenericError { + source: e.into(), + mod_info: mod_info.clone(), + })?; } _ => {} }