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::*;
|
use crate::utils::colors::*;
|
||||||
|
|
||||||
|
#[allow(missing_docs)]
|
||||||
/// All errors that can be generated by `ouch`
|
/// All errors that can be generated by `ouch`
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub enum Error {
|
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
|
/// Not every IoError, some of them get filtered by `From<io::Error>` into other variants
|
||||||
IoError {
|
IoError { reason: String },
|
||||||
/// TODO
|
|
||||||
reason: String,
|
|
||||||
},
|
|
||||||
/// Detected from io::Error if .kind() is io::ErrorKind::NotFound
|
/// Detected from io::Error if .kind() is io::ErrorKind::NotFound
|
||||||
FileNotFound(PathBuf),
|
FileNotFound(PathBuf),
|
||||||
/// TO BE REMOVED
|
/// NEEDS MORE CONTEXT
|
||||||
AlreadyExists,
|
AlreadyExists,
|
||||||
/// TO BE REMOVED
|
/// From zip::result::ZipError::InvalidArchive
|
||||||
InvalidZipArchive(&'static str),
|
InvalidZipArchive(&'static str),
|
||||||
/// Detected from io::Error if .kind() is io::ErrorKind::PermissionDenied
|
/// Detected from io::Error if .kind() is io::ErrorKind::PermissionDenied
|
||||||
PermissionDenied {
|
PermissionDenied { error_title: String },
|
||||||
/// TODO
|
/// From zip::result::ZipError::UnsupportedArchive
|
||||||
error_title: String,
|
|
||||||
},
|
|
||||||
/// TO BE REMOVED
|
|
||||||
UnsupportedZipArchive(&'static str),
|
UnsupportedZipArchive(&'static str),
|
||||||
/// TO BE REMOVED
|
/// TO BE REMOVED
|
||||||
CompressingRootFolder,
|
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
|
/// Specialized walkdir's io::Error wrapper with additional information on the error
|
||||||
WalkdirError {
|
WalkdirError { reason: String },
|
||||||
/// TODO
|
|
||||||
reason: String,
|
|
||||||
},
|
|
||||||
/// Custom and unique errors are reported in this variant
|
/// Custom and unique errors are reported in this variant
|
||||||
Custom {
|
Custom { reason: FinalError },
|
||||||
/// TODO
|
|
||||||
reason: FinalError,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Alias to std's Result with ouch's Error
|
/// Alias to std's Result with ouch's Error
|
||||||
@ -113,12 +92,6 @@ impl FinalError {
|
|||||||
impl fmt::Display for Error {
|
impl fmt::Display for Error {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
let err = match self {
|
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::WalkdirError { reason } => FinalError::with_title(reason),
|
||||||
Error::FileNotFound(file) => {
|
Error::FileNotFound(file) => {
|
||||||
if file == Path::new("") {
|
if file == Path::new("") {
|
||||||
@ -132,29 +105,7 @@ impl fmt::Display for Error {
|
|||||||
.detail("This is unadvisable since ouch does compressions in-memory.")
|
.detail("This is unadvisable since ouch does compressions in-memory.")
|
||||||
.hint("Use a more appropriate tool for this, such as rsync.")
|
.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::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::AlreadyExists => todo!(),
|
||||||
Error::InvalidZipArchive(_) => todo!(),
|
Error::InvalidZipArchive(_) => todo!(),
|
||||||
Error::PermissionDenied { error_title } => FinalError::with_title(error_title).detail("Permission denied"),
|
Error::PermissionDenied { error_title } => FinalError::with_title(error_title).detail("Permission denied"),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user