1 use std::{fmt, path::PathBuf};
5 #[derive(PartialEq, Eq, Debug)]
7 UnknownExtensionError(String),
8 MissingExtensionError(String),
9 // TODO: get rid of this error variant
13 FileNotFound(PathBuf),
15 InvalidZipArchive(&'static str),
17 UnsupportedZipArchive(&'static str),
18 InputsMustHaveBeenDecompressible(PathBuf),
22 pub type Result<T> = std::result::Result<T, Error>;
24 impl fmt::Display for Error {
25 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
26 write!(f, "{} ", "[ERROR]".red())?;
28 Error::MissingExtensionError(filename) => {
29 write!(f, "cannot compress to \'{}\', likely because it has an unsupported (or missing) extension.", filename)
31 Error::InputsMustHaveBeenDecompressible(file) => {
32 write!(f, "file '{:?}' is not decompressible", file)
34 Error::FileNotFound(file) => {
35 // TODO: check if file == ""
36 write!(f, "file {:?} not found!", file)
46 impl From<std::io::Error> for Error {
47 fn from(err: std::io::Error) -> Self {
49 std::io::ErrorKind::NotFound => Self::FileNotFound("".into()),
50 std::io::ErrorKind::PermissionDenied => Self::PermissionDenied,
51 std::io::ErrorKind::AlreadyExists => Self::AlreadyExists,
53 println!("{}: {}", "IO error".red(), err);
60 impl From<zip::result::ZipError> for Error {
61 fn from(err: zip::result::ZipError) -> Self {
62 use zip::result::ZipError::*;
64 Io(io_err) => Self::from(io_err),
65 InvalidArchive(filename) => Self::InvalidZipArchive(filename),
66 FileNotFound => Self::FileNotFound("".into()),
67 UnsupportedArchive(filename) => Self::UnsupportedZipArchive(filename),
72 impl From<walkdir::Error> for Error {
73 fn from(err: walkdir::Error) -> Self {
74 eprintln!("{}: {}", "error".red(), err);