Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MRG: propagate zipfile errors #3431

Merged
merged 7 commits into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading