mirror of
https://github.com/ouch-org/ouch.git
synced 2025-07-22 17:40:17 +00:00
Fixing Oof and Walkdir Error Display
This commit is contained in:
parent
d1734b54cb
commit
bf8ef70d16
20
src/error.rs
20
src/error.rs
@ -16,11 +16,11 @@ pub enum Error {
|
|||||||
PermissionDenied,
|
PermissionDenied,
|
||||||
UnsupportedZipArchive(&'static str),
|
UnsupportedZipArchive(&'static str),
|
||||||
InternalError,
|
InternalError,
|
||||||
OofError,
|
OofError(oof::OofError),
|
||||||
CompressingRootFolder,
|
CompressingRootFolder,
|
||||||
MissingArgumentsForCompression,
|
MissingArgumentsForCompression,
|
||||||
CompressionTypo,
|
CompressionTypo,
|
||||||
WalkdirError,
|
WalkdirError { reason: String },
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type Result<T> = std::result::Result<T, Error>;
|
pub type Result<T> = std::result::Result<T, Error>;
|
||||||
@ -33,9 +33,8 @@ impl fmt::Display for Error {
|
|||||||
// TODO: show MIME type of the unsupported file
|
// TODO: show MIME type of the unsupported file
|
||||||
write!(f, "cannot compress to {:?}, likely because it has an unsupported (or missing) extension.", filename)
|
write!(f, "cannot compress to {:?}, likely because it has an unsupported (or missing) extension.", filename)
|
||||||
},
|
},
|
||||||
Error::WalkdirError => {
|
Error::WalkdirError { reason } => {
|
||||||
// Already printed in the From block
|
write!(f, "{}[ERROR]{} {}", colors::red(), colors::reset(), reason)
|
||||||
write!(f, "")
|
|
||||||
},
|
},
|
||||||
Error::FileNotFound(file) => {
|
Error::FileNotFound(file) => {
|
||||||
write!(f, "{}[ERROR]{} ", colors::red(), colors::reset())?;
|
write!(f, "{}[ERROR]{} ", colors::red(), colors::reset())?;
|
||||||
@ -72,6 +71,9 @@ impl fmt::Display for Error {
|
|||||||
write!(f, "{}[ERROR]{} ", colors::red(), colors::reset())?;
|
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())
|
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::OofError(err) => {
|
||||||
|
write!(f, "{}[ERROR]{} {}", colors::red(), colors::reset(), err)
|
||||||
|
},
|
||||||
Error::IoError { reason } => {
|
Error::IoError { reason } => {
|
||||||
write!(f, "{}[ERROR]{} {}", colors::red(), colors::reset(), reason)
|
write!(f, "{}[ERROR]{} {}", colors::red(), colors::reset(), reason)
|
||||||
},
|
},
|
||||||
@ -110,16 +112,12 @@ impl From<zip::result::ZipError> for Error {
|
|||||||
|
|
||||||
impl From<walkdir::Error> for Error {
|
impl From<walkdir::Error> for Error {
|
||||||
fn from(err: walkdir::Error) -> Self {
|
fn from(err: walkdir::Error) -> Self {
|
||||||
eprintln!("{}[ERROR]{} {}", colors::red(), colors::reset(), err);
|
Self::WalkdirError { reason: err.to_string() }
|
||||||
Self::WalkdirError
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<oof::OofError> for Error {
|
impl From<oof::OofError> for Error {
|
||||||
fn from(err: oof::OofError) -> Self {
|
fn from(err: oof::OofError) -> Self {
|
||||||
// To avoid entering a lifetime hell, we'll just print the Oof error here
|
Self::OofError(err)
|
||||||
// and skip saving it into a variant of Self
|
|
||||||
println!("{}[ERROR]{} {}", colors::red(), colors::reset(), err);
|
|
||||||
Self::OofError
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ use std::{error, ffi::OsString, fmt};
|
|||||||
|
|
||||||
use super::Flag;
|
use super::Flag;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub enum OofError {
|
pub enum OofError {
|
||||||
FlagValueConflict {
|
FlagValueConflict {
|
||||||
flag: Flag,
|
flag: Flag,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user