Skip to content

Commit ad23a7b

Browse files
committed
Improve asset registry error handling
1 parent 69b3d8e commit ad23a7b

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/integrate.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,24 +162,33 @@ pub enum IntegrationError {
162162
RepakError { source: repak::Error },
163163
#[snafu(transparent)]
164164
UnrealAssetError { source: unreal_asset::Error },
165-
#[snafu(display("mod {}: I/O error encountered during its processing", mod_info.name))]
165+
#[snafu(display("mod {:?}: I/O error encountered during its processing", mod_info.name))]
166166
CtxtIoError {
167167
source: std::io::Error,
168168
mod_info: ModInfo,
169169
},
170-
#[snafu(display("mod {}: repak error encountered during its processing", mod_info.name))]
170+
#[snafu(display("mod {:?}: repak error encountered during its processing", mod_info.name))]
171171
CtxtRepakError {
172172
source: repak::Error,
173173
mod_info: ModInfo,
174174
},
175175
#[snafu(display(
176-
"modfile {} of mod {mod_info:?} contains unexpected prefix",
176+
"mod {:?}: modfile {} contains unexpected prefix",
177+
mod_info.name,
177178
modfile_path
178179
))]
179180
ModfileInvalidPrefix {
180181
mod_info: ModInfo,
181182
modfile_path: String,
182183
},
184+
#[snafu(display(
185+
"mod {:?}: failed to integrate: {source}",
186+
mod_info.name,
187+
))]
188+
CtxtGenericError {
189+
source: Box<dyn std::error::Error + Send + Sync>,
190+
mod_info: ModInfo,
191+
},
183192
#[snafu(transparent)]
184193
ProviderError { source: ProviderError },
185194
#[snafu(display("integration error: {msg}"))]
@@ -199,6 +208,7 @@ impl IntegrationError {
199208
match self {
200209
IntegrationError::CtxtIoError { mod_info, .. }
201210
| IntegrationError::CtxtRepakError { mod_info, .. }
211+
| IntegrationError::CtxtGenericError { mod_info, .. }
202212
| IntegrationError::ModfileInvalidPrefix { mod_info, .. } => mod_info.modio_id,
203213
IntegrationError::ProviderError { source } => source.opt_mod_id(),
204214
_ => None,
@@ -382,7 +392,10 @@ pub fn integrate<P: AsRef<Path>>(
382392
.build()?;
383393
asset_registry
384394
.populate(normalized.with_extension("").as_str(), &asset)
385-
.map_err(|e| IntegrationError::GenericError { msg: e.to_string() })?;
395+
.map_err(|e| IntegrationError::CtxtGenericError {
396+
source: e.into(),
397+
mod_info: mod_info.clone(),
398+
})?;
386399
}
387400
_ => {}
388401
}

0 commit comments

Comments
 (0)