s_zip/
error.rs

1//! Error types for s-zip
2
3use std::io;
4
5/// Result type for s-zip operations
6pub type Result<T> = std::result::Result<T, SZipError>;
7
8/// Error types that can occur during ZIP operations
9#[derive(Debug)]
10pub enum SZipError {
11    /// I/O error
12    Io(io::Error),
13    /// Invalid ZIP format or structure
14    InvalidFormat(String),
15    /// Entry not found in ZIP archive
16    EntryNotFound(String),
17    /// Unsupported compression method
18    UnsupportedCompression(u16),
19    /// Encryption/decryption error
20    #[cfg(feature = "encryption")]
21    EncryptionError(String),
22    /// Incorrect password
23    #[cfg(feature = "encryption")]
24    IncorrectPassword,
25}
26
27impl std::fmt::Display for SZipError {
28    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
29        match self {
30            SZipError::Io(e) => write!(f, "I/O error: {}", e),
31            SZipError::InvalidFormat(msg) => write!(f, "Invalid ZIP format: {}", msg),
32            SZipError::EntryNotFound(name) => write!(f, "Entry not found: {}", name),
33            SZipError::UnsupportedCompression(method) => {
34                write!(f, "Unsupported compression method: {}", method)
35            }
36            #[cfg(feature = "encryption")]
37            SZipError::EncryptionError(msg) => write!(f, "Encryption error: {}", msg),
38            #[cfg(feature = "encryption")]
39            SZipError::IncorrectPassword => write!(f, "Incorrect password"),
40        }
41    }
42}
43
44impl std::error::Error for SZipError {}
45
46impl From<io::Error> for SZipError {
47    fn from(err: io::Error) -> Self {
48        SZipError::Io(err)
49    }
50}