blob: e8b7d05214ece8f34324f8bcba0ec739d5d9aa93 [file] [log] [blame]
Yi Kongf19c3f22021-02-13 04:04:00 +08001//! Error types that can be emitted from this library
2
3use std::io;
4
5use thiserror::Error;
6
7/// Generic result type with ZipError as its error variant
8pub 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")]
13pub struct InvalidPassword;
14
15/// Error type for Zip
16#[derive(Debug, Error)]
17pub 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
35impl From<ZipError> for io::Error {
36 fn from(err: ZipError) -> io::Error {
37 io::Error::new(io::ErrorKind::Other, err)
38 }
39}