Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 1 addition & 3 deletions src/compression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,9 +513,7 @@ impl<R: io::BufRead> Decompressor<R> {
crate::legacy::implode::ImplodeDecoder::new(reader, uncompressed_size, flags),
),
_ => {
return Err(crate::result::ZipError::UnsupportedArchive(
"Compression method not supported",
));
return Err(crate::result::ZipError::CompressionMethodNotSupported);
Comment thread
Its-Just-Nans marked this conversation as resolved.
Outdated
}
})
}
Expand Down
4 changes: 1 addition & 3 deletions src/read/readers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,7 @@ pub(crate) fn make_crypto_reader<'a, R: Read + ?Sized>(
#[allow(deprecated)]
{
if let CompressionMethod::Unsupported(_) = data.compression_method {
return Err(ZipError::UnsupportedArchive(
"Compression method not supported",
));
return Err(ZipError::CompressionMethodNotSupported);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Capture the unsupported compression method ID and pass it to the error variant for better diagnostics.

Suggested change
if let CompressionMethod::Unsupported(_) = data.compression_method {
return Err(ZipError::UnsupportedArchive(
"Compression method not supported",
));
return Err(ZipError::CompressionMethodNotSupported);
if let CompressionMethod::Unsupported(id) = data.compression_method {
return Err(ZipError::CompressionMethodNotSupported(id));
References
  1. When changing the type of a field, ensure all implementations that use this field are updated accordingly to avoid compilation errors.

}
}

Expand Down
11 changes: 9 additions & 2 deletions src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ pub enum ZipError {

/// provided password is incorrect
InvalidPassword,

/// Compression method not supported
CompressionMethodNotSupported,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also expose the compression method used? Ideally in a way that we can both Display and read the compression number from. Otherwise we can't give the full information to the user.

Comment thread
Its-Just-Nans marked this conversation as resolved.
Outdated
}

impl ZipError {
Expand All @@ -52,6 +55,7 @@ impl Display for ZipError {
Self::UnsupportedArchive(e) => write!(f, "unsupported Zip archive: {e}"),
Self::FileNotFound => f.write_str("specified file not found in archive"),
Self::InvalidPassword => f.write_str("provided password is incorrect"),
Self::CompressionMethodNotSupported => f.write_str("compression method not supported"),
Comment thread
Its-Just-Nans marked this conversation as resolved.
Outdated
}
}
}
Expand All @@ -63,7 +67,8 @@ impl Error for ZipError {
Self::InvalidArchive(_)
| Self::UnsupportedArchive(_)
| Self::FileNotFound
| Self::InvalidPassword => None,
| Self::InvalidPassword
| Self::CompressionMethodNotSupported => None,
Comment thread
Its-Just-Nans marked this conversation as resolved.
Outdated
}
}
}
Expand All @@ -73,7 +78,9 @@ impl From<ZipError> for io::Error {
let kind = match &err {
ZipError::Io(err) => err.kind(),
ZipError::InvalidArchive(_) => io::ErrorKind::InvalidData,
ZipError::UnsupportedArchive(_) => io::ErrorKind::Unsupported,
ZipError::UnsupportedArchive(_) | ZipError::CompressionMethodNotSupported => {
io::ErrorKind::Unsupported
}
Comment thread
Its-Just-Nans marked this conversation as resolved.
Outdated
ZipError::FileNotFound => io::ErrorKind::NotFound,
ZipError::InvalidPassword => io::ErrorKind::InvalidInput,
};
Expand Down
Loading