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),
21 pub type OuchResult<T> = Result<T, Error>;
23 impl fmt::Display for Error {
24 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
25 write!(f, "{} ", "[ERROR]".red())?;
27 Error::MissingExtensionError(filename) => {
28 write!(f, "cannot compress to \'{}\', likely because it has an unsupported (or missing) extension.", filename)
30 Error::InputsMustHaveBeenDecompressible(file) => {
31 write!(f, "file '{:?}' is not decompressible", file)
33 Error::FileNotFound(file) => {
34 // TODO: check if file == ""
35 write!(f, "file {:?} not found!", file)
45 impl From<std::io::Error> for Error {
46 fn from(err: std::io::Error) -> Self {
48 std::io::ErrorKind::NotFound => Self::FileNotFound("".into()),
49 std::io::ErrorKind::PermissionDenied => Self::PermissionDenied,
50 std::io::ErrorKind::AlreadyExists => Self::AlreadyExists,
52 println!("{}: {}", "IO error".red(), err);
59 impl From<zip::result::ZipError> for Error {
60 fn from(err: zip::result::ZipError) -> Self {
61 use zip::result::ZipError::*;
63 Io(io_err) => Self::from(io_err),
64 InvalidArchive(filename) => Self::InvalidZipArchive(filename),
65 FileNotFound => Self::FileNotFound("".into()),
66 UnsupportedArchive(filename) => Self::UnsupportedZipArchive(filename)
71 impl From<walkdir::Error> for Error {
72 fn from(err: walkdir::Error) -> Self {
73 eprintln!("{}: {}", "error".red(), err);