Skip to content

Commit ee96390

Browse files
committed
frontend_utils: Improve errors for invalid bundle archives
This simplifies code and adds some context to errors.
1 parent 4829059 commit ee96390

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

frontend-utils/src/bundle/source.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use ::zip::result::ZipError;
2+
13
use crate::bundle::info::BUNDLE_INFORMATION_FILENAME;
24
use crate::bundle::source::zip::ZipSource;
35
use std::ffi::OsStr;
@@ -31,8 +33,8 @@ pub enum BundleSourceError {
3133
#[error("Unknown bundle source")]
3234
UnknownSource,
3335

34-
#[error("Invalid or corrupt zip")]
35-
InvalidZip,
36+
#[error("Invalid or corrupt archive: {0}")]
37+
InvalidArchive(#[from] ZipError),
3638

3739
#[error("IO error opening file: {0}")]
3840
Io(#[from] Error),
@@ -65,11 +67,8 @@ impl BundleSource {
6567
}
6668

6769
pub fn from_reader<R: Read + Seek + 'static>(reader: R) -> Result<Self, BundleSourceError> {
68-
return if let Ok(zip) = ZipSource::<Box<dyn BundleSourceData>>::open(Box::new(reader)) {
69-
Ok(Self::ZipFile(zip))
70-
} else {
71-
Err(BundleSourceError::InvalidZip)
72-
};
70+
let zip_source = ZipSource::<Box<dyn BundleSourceData>>::open(Box::new(reader))?;
71+
Ok(Self::ZipFile(zip_source))
7372
}
7473

7574
/// Reads any file from the bundle.

0 commit comments

Comments
 (0)