mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-07 12:05:46 +00:00
Removing obsolete error variants
This commit is contained in:
parent
5c0f24f567
commit
2fcec33ec6
65
src/error.rs
65
src/error.rs
@ -9,49 +9,28 @@ use std::{
|
||||
|
||||
use crate::utils::colors::*;
|
||||
|
||||
#[allow(missing_docs)]
|
||||
/// All errors that can be generated by `ouch`
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum Error {
|
||||
/// Extension found is not supported and known to ouch
|
||||
UnknownExtensionError(String),
|
||||
/// TO BE REMOVED
|
||||
MissingExtensionError(PathBuf),
|
||||
/// Not every IoError, some of them get filtered by `From<io::Error>` into other variants
|
||||
IoError {
|
||||
/// TODO
|
||||
reason: String,
|
||||
},
|
||||
IoError { reason: String },
|
||||
/// Detected from io::Error if .kind() is io::ErrorKind::NotFound
|
||||
FileNotFound(PathBuf),
|
||||
/// TO BE REMOVED
|
||||
/// NEEDS MORE CONTEXT
|
||||
AlreadyExists,
|
||||
/// TO BE REMOVED
|
||||
/// From zip::result::ZipError::InvalidArchive
|
||||
InvalidZipArchive(&'static str),
|
||||
/// Detected from io::Error if .kind() is io::ErrorKind::PermissionDenied
|
||||
PermissionDenied {
|
||||
/// TODO
|
||||
error_title: String,
|
||||
},
|
||||
/// TO BE REMOVED
|
||||
PermissionDenied { error_title: String },
|
||||
/// From zip::result::ZipError::UnsupportedArchive
|
||||
UnsupportedZipArchive(&'static str),
|
||||
/// TO BE REMOVED
|
||||
CompressingRootFolder,
|
||||
/// TO BE REMOVED
|
||||
MissingArgumentsForCompression,
|
||||
/// TO BE REMOVED
|
||||
MissingArgumentsForDecompression,
|
||||
/// TO BE REMOVED
|
||||
CompressionTypo,
|
||||
/// Specialized walkdir's io::Error wrapper with additional information on the error
|
||||
WalkdirError {
|
||||
/// TODO
|
||||
reason: String,
|
||||
},
|
||||
WalkdirError { reason: String },
|
||||
/// Custom and unique errors are reported in this variant
|
||||
Custom {
|
||||
/// TODO
|
||||
reason: FinalError,
|
||||
},
|
||||
Custom { reason: FinalError },
|
||||
}
|
||||
|
||||
/// Alias to std's Result with ouch's Error
|
||||
@ -113,12 +92,6 @@ impl FinalError {
|
||||
impl fmt::Display for Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
let err = match self {
|
||||
Error::MissingExtensionError(filename) => {
|
||||
FinalError::with_title(format!("Cannot compress to {:?}", filename))
|
||||
.detail("Ouch could not detect the compression format")
|
||||
.hint("Use a supported format extension, like '.zip' or '.tar.gz'")
|
||||
.hint("Check https://github.com/ouch-org/ouch for a full list of supported formats")
|
||||
}
|
||||
Error::WalkdirError { reason } => FinalError::with_title(reason),
|
||||
Error::FileNotFound(file) => {
|
||||
if file == Path::new("") {
|
||||
@ -132,29 +105,7 @@ impl fmt::Display for Error {
|
||||
.detail("This is unadvisable since ouch does compressions in-memory.")
|
||||
.hint("Use a more appropriate tool for this, such as rsync.")
|
||||
}
|
||||
Error::MissingArgumentsForCompression => {
|
||||
FinalError::with_title("Could not compress")
|
||||
.detail("The compress command requires at least 2 arguments")
|
||||
.hint("You must provide:")
|
||||
.hint(" - At least one input argument.")
|
||||
.hint(" - The output argument.")
|
||||
.hint("")
|
||||
.hint("Example: `ouch compress image.png img.zip`")
|
||||
}
|
||||
Error::MissingArgumentsForDecompression => {
|
||||
FinalError::with_title("Could not decompress")
|
||||
.detail("The compress command requires at least one argument")
|
||||
.hint("You must provide:")
|
||||
.hint(" - At least one input argument.")
|
||||
.hint("")
|
||||
.hint("Example: `ouch decompress imgs.tar.gz`")
|
||||
}
|
||||
Error::IoError { reason } => FinalError::with_title(reason),
|
||||
Error::CompressionTypo => {
|
||||
FinalError::with_title("Possible typo detected")
|
||||
.hint(format!("Did you mean '{}ouch compress{}'?", *MAGENTA, *RESET))
|
||||
}
|
||||
Error::UnknownExtensionError(_) => todo!(),
|
||||
Error::AlreadyExists => todo!(),
|
||||
Error::InvalidZipArchive(_) => todo!(),
|
||||
Error::PermissionDenied { error_title } => FinalError::with_title(error_title).detail("Permission denied"),
|
||||
|
Loading…
x
Reference in New Issue
Block a user