diff --git a/src/cli.rs b/src/cli.rs index 382aeff..efab31e 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -179,7 +179,6 @@ impl TryFrom> for Command { output: Some(File { path: output_file.into(), contents_in_memory: None, - // extension: output_file_extension.ok(), extension: Some(output_file_extension.unwrap()), }), }) diff --git a/src/compressors/bzip.rs b/src/compressors/bzip.rs index cd5e58c..d2a20d0 100644 --- a/src/compressors/bzip.rs +++ b/src/compressors/bzip.rs @@ -36,8 +36,7 @@ impl BzipCompressor { let bytes = match file.contents_in_memory { Some(bytes) => bytes, None => { - // TODO: error message, - return Err(crate::Error::InvalidInput); + return Err(crate::Error::InternalError); } }; diff --git a/src/compressors/tar.rs b/src/compressors/tar.rs index d7a014b..0bf89ff 100644 --- a/src/compressors/tar.rs +++ b/src/compressors/tar.rs @@ -14,8 +14,8 @@ impl TarCompressor { // TODO: implement this fn make_archive_from_memory(_input: File) -> crate::Result> { println!( - "{}: .tar.tar and .zip.tar is currently unimplemented.", - "error".red() + "{} .tar.tar and .zip.tar is currently unimplemented.", + "[ERROR]".red() ); Err(crate::Error::InvalidZipArchive("")) } diff --git a/src/error.rs b/src/error.rs index 57d1403..60f8316 100644 --- a/src/error.rs +++ b/src/error.rs @@ -18,6 +18,7 @@ pub enum Error { InputsMustHaveBeenDecompressible(PathBuf), InternalError, CompressingRootFolder, + WalkdirError } pub type Result = std::result::Result; @@ -38,25 +39,33 @@ impl fmt::Debug for Error { impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{} ", "[ERROR]".red())?; match self { Error::MissingExtensionError(filename) => { + write!(f, "{} ", "[ERROR]".red())?; write!(f, "cannot compress to \'{}\', likely because it has an unsupported (or missing) extension.", filename) } Error::InputsMustHaveBeenDecompressible(file) => { + write!(f, "{} ", "[ERROR]".red())?; write!(f, "file '{:?}' is not decompressible", file) } + Error::WalkdirError => { + // Already printed in the From block + write!(f, "") + } Error::FileNotFound(file) => { + write!(f, "{} ", "[ERROR]".red())?; // TODO: check if file == "" write!(f, "file {:?} not found!", file) } Error::CompressingRootFolder => { + write!(f, "{} ", "[ERROR]".red())?; let spacing = " "; writeln!(f, "It seems you're trying to compress the root folder.")?; writeln!(f, "{}This is unadvisable since ouch does compressions in-memory.", spacing)?; write!(f, "{}Use a more appropriate tool for this, such as {}.", spacing, "rsync".green()) } Error::InternalError => { + write!(f, "{} ", "[ERROR]".red())?; write!(f, "You've reached an internal error! This really should not have happened.\nPlease file an issue at {}", "https://github.com/vrmiguel/ouch".green()) } _err => { @@ -74,7 +83,7 @@ impl From for Error { std::io::ErrorKind::PermissionDenied => Self::PermissionDenied, std::io::ErrorKind::AlreadyExists => Self::AlreadyExists, _other => { - println!("{}: {}", "IO error".red(), err); + println!("{} {}", "[IO error]".red(), err); Self::IoError } } @@ -95,7 +104,7 @@ impl From for Error { impl From for Error { fn from(err: walkdir::Error) -> Self { - eprintln!("{}: {}", "error".red(), err); - Self::InvalidInput + eprintln!("{} {}", "[ERROR]".red(), err); + Self::WalkdirError } } diff --git a/src/evaluator.rs b/src/evaluator.rs index 959a939..105ed26 100644 --- a/src/evaluator.rs +++ b/src/evaluator.rs @@ -29,10 +29,10 @@ impl Evaluator { None => { // This block *should* be unreachable eprintln!( - "{}: reached Evaluator::get_decompressor without known extension.", - "internal error".red() + "{} reached Evaluator::get_decompressor without known extension.", + "[internal error]".red() ); - return Err(crate::Error::InvalidInput); + return Err(crate::Error::InternalError); } }; @@ -71,8 +71,8 @@ impl Evaluator { None => { // This block *should* be unreachable eprintln!( - "{}: reached Evaluator::get_decompressor without known extension.", - "internal error".red() + "{} reached Evaluator::get_decompressor without known extension.", + "[internal error]".red() ); return Err(crate::Error::InvalidInput); } diff --git a/src/utils.rs b/src/utils.rs index af5a438..c131fce 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -13,11 +13,6 @@ where { let exists = path.as_ref().exists(); if !exists { - eprintln!( - "{}: could not find file {:?}", - "[ERROR]".red(), - path.as_ref() - ); return Err(crate::Error::FileNotFound(PathBuf::from(path.as_ref()))); } Ok(())