Skip to content

Commit

Permalink
Improve asset registry error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
trumank committed Apr 23, 2024
1 parent 123cfec commit 9bc18cb
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/integrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn std::error::Error + Send + Sync>,
mod_info: ModInfo,
},
#[snafu(transparent)]
ProviderError { source: ProviderError },
#[snafu(display("integration error: {msg}"))]
Expand All @@ -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,
Expand Down Expand Up @@ -382,7 +392,10 @@ pub fn integrate<P: AsRef<Path>>(
.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(),
})?;
}
_ => {}
}
Expand Down

0 comments on commit 9bc18cb

Please sign in to comment.