Skip to content

Commit

Permalink
MRG: propagate zipfile errors (#3431)
Browse files Browse the repository at this point in the history
This PR switches from `ZipStorageBuilder` to `ZipStorageTryBuilder` in
order to propagate errors from bad zip files.

Fixes #3430
  • Loading branch information
ctb authored Dec 15, 2024
1 parent 7362b43 commit d814ba7
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions include/sourmash.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ enum SourmashErrorCode {
SOURMASH_ERROR_CODE_NIFFLER_ERROR = 100005,
SOURMASH_ERROR_CODE_CSV_ERROR = 100006,
SOURMASH_ERROR_CODE_ROCKS_DB_ERROR = 100007,
SOURMASH_ERROR_CODE_ZIP_ERROR = 100008,
};
typedef uint32_t SourmashErrorCode;

Expand Down
2 changes: 1 addition & 1 deletion src/core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sourmash"
version = "0.17.2"
version = "0.18.0"
authors = ["Luiz Irber <[email protected]>", "N. Tessa Pierce-Ward <[email protected]>", "C. Titus Brown <[email protected]>"]
description = "tools for comparing biological sequences with k-mer sketches"
repository = "https://github.com/sourmash-bio/sourmash"
Expand Down
6 changes: 6 additions & 0 deletions src/core/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ pub enum SourmashError {
#[cfg(feature = "branchwater")]
#[error(transparent)]
RocksDBError(#[from] rocksdb::Error),

#[error(transparent)]
ZipError(#[from] piz::result::ZipError),
}

#[derive(Debug, Error)]
Expand Down Expand Up @@ -140,6 +143,7 @@ pub enum SourmashErrorCode {
NifflerError = 100_005,
CsvError = 100_006,
RocksDBError = 100_007,
ZipError = 100_008,
}

#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
Expand Down Expand Up @@ -179,6 +183,8 @@ impl SourmashErrorCode {
#[cfg(not(target_arch = "wasm32"))]
#[cfg(feature = "branchwater")]
SourmashError::RocksDBError { .. } => SourmashErrorCode::RocksDBError,

SourmashError::ZipError { .. } => SourmashErrorCode::ZipError,
}
}
}
10 changes: 5 additions & 5 deletions src/core/src/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,22 +403,22 @@ impl ZipStorage {
let zip_file = File::open(location.as_ref())?;
let mapping = unsafe { memmap2::Mmap::map(&zip_file)? };

let mut storage = ZipStorageBuilder {
let mut storage = ZipStorageTryBuilder {
mapping: Some(mapping),
archive_builder: |mapping: &Option<memmap2::Mmap>| {
piz::ZipArchive::new(mapping.as_ref().unwrap()).unwrap()
piz::ZipArchive::new(mapping.as_ref().unwrap())
},
metadata_builder: |archive: &piz::ZipArchive| {
archive
Ok(archive
.entries()
.iter()
.map(|entry| (entry.path.as_os_str(), entry))
.collect()
.collect())
},
subdir: None,
path: Some(location.as_ref().into()),
}
.build();
.try_build()?;

let subdir = find_subdirs(storage.borrow_archive())?;
storage.with_mut(|fields| *fields.subdir = subdir);
Expand Down

0 comments on commit d814ba7

Please sign in to comment.