mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 20:17:45 +00:00
du: move to thiserror
This commit is contained in:
parent
3fe1cbe71f
commit
096e41086d
2 changed files with 14 additions and 36 deletions
|
@ -22,6 +22,7 @@ chrono = { workspace = true }
|
||||||
glob = { workspace = true }
|
glob = { workspace = true }
|
||||||
clap = { workspace = true }
|
clap = { workspace = true }
|
||||||
uucore = { workspace = true, features = ["format"] }
|
uucore = { workspace = true, features = ["format"] }
|
||||||
|
thiserror = { workspace = true }
|
||||||
|
|
||||||
[target.'cfg(target_os = "windows")'.dependencies]
|
[target.'cfg(target_os = "windows")'.dependencies]
|
||||||
windows-sys = { workspace = true, features = [
|
windows-sys = { workspace = true, features = [
|
||||||
|
|
|
@ -8,8 +8,6 @@ use clap::{builder::PossibleValue, crate_version, Arg, ArgAction, ArgMatches, Co
|
||||||
use glob::Pattern;
|
use glob::Pattern;
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::error::Error;
|
|
||||||
use std::fmt::Display;
|
|
||||||
#[cfg(not(windows))]
|
#[cfg(not(windows))]
|
||||||
use std::fs::Metadata;
|
use std::fs::Metadata;
|
||||||
use std::fs::{self, DirEntry, File};
|
use std::fs::{self, DirEntry, File};
|
||||||
|
@ -25,6 +23,7 @@ use std::str::FromStr;
|
||||||
use std::sync::mpsc;
|
use std::sync::mpsc;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use std::time::{Duration, UNIX_EPOCH};
|
use std::time::{Duration, UNIX_EPOCH};
|
||||||
|
use thiserror::Error;
|
||||||
use uucore::display::{print_verbatim, Quotable};
|
use uucore::display::{print_verbatim, Quotable};
|
||||||
use uucore::error::{set_exit_code, FromIo, UError, UResult, USimpleError};
|
use uucore::error::{set_exit_code, FromIo, UError, UResult, USimpleError};
|
||||||
use uucore::line_ending::LineEnding;
|
use uucore::line_ending::LineEnding;
|
||||||
|
@ -409,48 +408,26 @@ fn du(
|
||||||
Ok(my_stat)
|
Ok(my_stat)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Error)]
|
||||||
enum DuError {
|
enum DuError {
|
||||||
|
#[error("invalid maximum depth {depth}", depth = .0.quote())]
|
||||||
InvalidMaxDepthArg(String),
|
InvalidMaxDepthArg(String),
|
||||||
|
|
||||||
|
#[error("summarizing conflicts with --max-depth={depth}", depth = .0.maybe_quote())]
|
||||||
SummarizeDepthConflict(String),
|
SummarizeDepthConflict(String),
|
||||||
|
|
||||||
|
#[error("invalid argument {style} for 'time style'\nValid arguments are:\n- 'full-iso'\n- 'long-iso'\n- 'iso'\nTry '{help}' for more information.",
|
||||||
|
style = .0.quote(),
|
||||||
|
help = uucore::execution_phrase())]
|
||||||
InvalidTimeStyleArg(String),
|
InvalidTimeStyleArg(String),
|
||||||
|
|
||||||
|
#[error("'birth' and 'creation' arguments for --time are not supported on this platform.")]
|
||||||
InvalidTimeArg,
|
InvalidTimeArg,
|
||||||
|
|
||||||
|
#[error("Invalid exclude syntax: {0}")]
|
||||||
InvalidGlob(String),
|
InvalidGlob(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for DuError {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
||||||
match self {
|
|
||||||
Self::InvalidMaxDepthArg(s) => write!(f, "invalid maximum depth {}", s.quote()),
|
|
||||||
Self::SummarizeDepthConflict(s) => {
|
|
||||||
write!(
|
|
||||||
f,
|
|
||||||
"summarizing conflicts with --max-depth={}",
|
|
||||||
s.maybe_quote()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
Self::InvalidTimeStyleArg(s) => write!(
|
|
||||||
f,
|
|
||||||
"invalid argument {} for 'time style'
|
|
||||||
Valid arguments are:
|
|
||||||
- 'full-iso'
|
|
||||||
- 'long-iso'
|
|
||||||
- 'iso'
|
|
||||||
Try '{} --help' for more information.",
|
|
||||||
s.quote(),
|
|
||||||
uucore::execution_phrase()
|
|
||||||
),
|
|
||||||
Self::InvalidTimeArg => write!(
|
|
||||||
f,
|
|
||||||
"'birth' and 'creation' arguments for --time are not supported on this platform.",
|
|
||||||
),
|
|
||||||
Self::InvalidGlob(s) => write!(f, "Invalid exclude syntax: {s}"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Error for DuError {}
|
|
||||||
|
|
||||||
impl UError for DuError {
|
impl UError for DuError {
|
||||||
fn code(&self) -> i32 {
|
fn code(&self) -> i32 {
|
||||||
match self {
|
match self {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue