diff --git a/src/cli.rs b/src/cli.rs index 05d8a4a..0ac0f2b 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -31,6 +31,7 @@ pub fn parse_args() -> crate::Result { parse_args_from(args) } +#[derive(Debug)] pub struct ParsedArgs { pub command: Command, pub flags: oof::Flags, @@ -63,7 +64,7 @@ where if !path.as_ref().exists() { Err(crate::Error::FileNotFound(PathBuf::from(path.as_ref()))) } else { - Err(crate::Error::IoError(io_err)) + Err(io_err.into()) } }, } diff --git a/src/error.rs b/src/error.rs index ab0d97e..d7380d1 100644 --- a/src/error.rs +++ b/src/error.rs @@ -2,13 +2,14 @@ use std::{fmt, path::PathBuf}; use crate::{oof, utils::colors}; +#[derive(Debug, PartialEq)] pub enum Error { UnknownExtensionError(String), MissingExtensionError(PathBuf), // TODO: get rid of this error variant InvalidUnicode, InvalidInput, - IoError(std::io::Error), + IoError { reason: String }, FileNotFound(PathBuf), AlreadyExists, InvalidZipArchive(&'static str), @@ -24,12 +25,6 @@ pub enum Error { pub type Result = std::result::Result; -impl fmt::Debug for Error { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{}", self) - } -} - impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { @@ -77,8 +72,8 @@ impl fmt::Display for Error { write!(f, "{}[ERROR]{} ", colors::red(), colors::reset())?; write!(f, "You've reached an internal error! This really should not have happened.\nPlease file an issue at {}https://github.com/vrmiguel/ouch{}", colors::green(), colors::reset()) }, - Error::IoError(io_err) => { - write!(f, "{}[ERROR]{} {}", colors::red(), colors::reset(), io_err) + Error::IoError { reason } => { + write!(f, "{}[ERROR]{} {}", colors::red(), colors::reset(), reason) }, Error::CompressionTypo => { write!(f, "Did you mean {}ouch compress{}?", colors::magenta(), colors::reset()) @@ -96,7 +91,7 @@ impl From for Error { std::io::ErrorKind::NotFound => panic!("{}", err), std::io::ErrorKind::PermissionDenied => Self::PermissionDenied, std::io::ErrorKind::AlreadyExists => Self::AlreadyExists, - _other => Self::IoError(err), + _other => Self::IoError { reason: err.to_string() }, } } }