5 #[derive(PartialEq, Eq, Debug)]
7 UnknownExtensionError(String),
8 MissingExtensionError(String),
9 // TODO: get rid of this error variant
15 InvalidZipArchive(&'static str),
17 UnsupportedZipArchive(&'static str),
19 InputsMustHaveBeenDecompressible(String),
22 pub type OuchResult<T> = Result<T, Error>;
24 impl fmt::Display for Error {
25 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
28 Error::InvalidInput => write!(
30 "When `-o/--output` is omitted, all input files should be compressed files."
32 Error::MissingExtensionError(filename) => {
33 write!(f, "cannot compress to \'{}\', likely because it has an unsupported (or missing) extension.", filename)
35 Error::InputsMustHaveBeenDecompressible(file) => {
36 write!(f, "file '{}' is not decompressible", file.red())
38 // TODO: find out a way to attach the missing file in question here
39 Error::FileNotFound => {
40 write!(f, "file not found!")
44 write!(f, "todo: missing description for error {:?}", err)
50 impl From<std::io::Error> for Error {
51 fn from(err: std::io::Error) -> Self {
53 std::io::ErrorKind::NotFound => Self::FileNotFound,
54 std::io::ErrorKind::PermissionDenied => Self::PermissionDenied,
55 std::io::ErrorKind::AlreadyExists => Self::AlreadyExists,
57 println!("{}: {:#?}", "IO error".red(), err);
64 impl From<zip::result::ZipError> for Error {
65 fn from(err: zip::result::ZipError) -> Self {
66 use zip::result::ZipError::*;
68 Io(io_err) => Self::from(io_err),
69 InvalidArchive(filename) => Self::InvalidZipArchive(filename),
70 FileNotFound => Self::FileNotFound,
71 UnsupportedArchive(filename) => Self::UnsupportedZipArchive(filename)
76 impl From<niffler::error::Error> for Error {
77 fn from(err: niffler::error::Error) -> Self {
78 use niffler::error::Error as NifErr;
80 NifErr::FeatureDisabled => {
81 // Ouch is using Niffler with all its features so
82 // this should be unreachable.
85 NifErr::FileTooShort => Self::FileTooShort,
86 NifErr::IOError(io_err) => Self::from(io_err)
91 impl From<walkdir::Error> for Error {
92 fn from(err: walkdir::Error) -> Self {
93 eprintln!("{}: {}", "error".red(), err);