Yi Kong | f19c3f2 | 2021-02-13 04:04:00 +0800 | [diff] [blame^] | 1 | //! Error types that can be emitted from this library |
| 2 | |
| 3 | use std::io; |
| 4 | |
| 5 | use thiserror::Error; |
| 6 | |
| 7 | /// Generic result type with ZipError as its error variant |
| 8 | pub type ZipResult<T> = Result<T, ZipError>; |
| 9 | |
| 10 | /// The given password is wrong |
| 11 | #[derive(Error, Debug)] |
| 12 | #[error("invalid password for file in archive")] |
| 13 | pub struct InvalidPassword; |
| 14 | |
| 15 | /// Error type for Zip |
| 16 | #[derive(Debug, Error)] |
| 17 | pub enum ZipError { |
| 18 | /// An Error caused by I/O |
| 19 | #[error(transparent)] |
| 20 | Io(#[from] io::Error), |
| 21 | |
| 22 | /// This file is probably not a zip archive |
| 23 | #[error("invalid Zip archive")] |
| 24 | InvalidArchive(&'static str), |
| 25 | |
| 26 | /// This archive is not supported |
| 27 | #[error("unsupported Zip archive")] |
| 28 | UnsupportedArchive(&'static str), |
| 29 | |
| 30 | /// The requested file could not be found in the archive |
| 31 | #[error("specified file not found in archive")] |
| 32 | FileNotFound, |
| 33 | } |
| 34 | |
| 35 | impl From<ZipError> for io::Error { |
| 36 | fn from(err: ZipError) -> io::Error { |
| 37 | io::Error::new(io::ErrorKind::Other, err) |
| 38 | } |
| 39 | } |