mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 12:07:46 +00:00
dd: move to thiserror
This commit is contained in:
parent
047d9a930b
commit
4f1d33fec3
3 changed files with 18 additions and 65 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -2662,6 +2662,7 @@ dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"nix",
|
"nix",
|
||||||
"signal-hook",
|
"signal-hook",
|
||||||
|
"thiserror 2.0.12",
|
||||||
"uucore",
|
"uucore",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ clap = { workspace = true }
|
||||||
gcd = { workspace = true }
|
gcd = { workspace = true }
|
||||||
libc = { workspace = true }
|
libc = { workspace = true }
|
||||||
uucore = { workspace = true, features = ["format", "quoting-style"] }
|
uucore = { workspace = true, features = ["format", "quoting-style"] }
|
||||||
|
thiserror = { workspace = true }
|
||||||
|
|
||||||
[target.'cfg(any(target_os = "linux", target_os = "android"))'.dependencies]
|
[target.'cfg(any(target_os = "linux", target_os = "android"))'.dependencies]
|
||||||
signal-hook = { workspace = true }
|
signal-hook = { workspace = true }
|
||||||
|
|
|
@ -9,28 +9,42 @@ mod unit_tests;
|
||||||
|
|
||||||
use super::{ConversionMode, IConvFlags, IFlags, Num, OConvFlags, OFlags, Settings, StatusLevel};
|
use super::{ConversionMode, IConvFlags, IFlags, Num, OConvFlags, OFlags, Settings, StatusLevel};
|
||||||
use crate::conversion_tables::ConversionTable;
|
use crate::conversion_tables::ConversionTable;
|
||||||
use std::error::Error;
|
use thiserror::Error;
|
||||||
use uucore::display::Quotable;
|
use uucore::display::Quotable;
|
||||||
use uucore::error::UError;
|
use uucore::error::UError;
|
||||||
use uucore::parse_size::{ParseSizeError, Parser as SizeParser};
|
use uucore::parse_size::{ParseSizeError, Parser as SizeParser};
|
||||||
use uucore::show_warning;
|
use uucore::show_warning;
|
||||||
|
|
||||||
/// Parser Errors describe errors with parser input
|
/// Parser Errors describe errors with parser input
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
#[derive(Debug, PartialEq, Eq, Error)]
|
||||||
pub enum ParseError {
|
pub enum ParseError {
|
||||||
|
#[error("Unrecognized operand '{0}'")]
|
||||||
UnrecognizedOperand(String),
|
UnrecognizedOperand(String),
|
||||||
|
#[error("Only one of conv=ascii conv=ebcdic or conv=ibm may be specified")]
|
||||||
MultipleFmtTable,
|
MultipleFmtTable,
|
||||||
|
#[error("Only one of conv=lcase or conv=ucase may be specified")]
|
||||||
MultipleUCaseLCase,
|
MultipleUCaseLCase,
|
||||||
|
#[error("Only one of conv=block or conv=unblock may be specified")]
|
||||||
MultipleBlockUnblock,
|
MultipleBlockUnblock,
|
||||||
|
#[error("Only one ov conv=excl or conv=nocreat may be specified")]
|
||||||
MultipleExclNoCreate,
|
MultipleExclNoCreate,
|
||||||
|
#[error("invalid input flag: ‘{}’\nTry '{} --help' for more information.", .0, uucore::execution_phrase())]
|
||||||
FlagNoMatch(String),
|
FlagNoMatch(String),
|
||||||
|
#[error("Unrecognized conv=CONV -> {0}")]
|
||||||
ConvFlagNoMatch(String),
|
ConvFlagNoMatch(String),
|
||||||
|
#[error("invalid number: ‘{0}’")]
|
||||||
MultiplierStringParseFailure(String),
|
MultiplierStringParseFailure(String),
|
||||||
|
#[error("Multiplier string would overflow on current system -> {0}")]
|
||||||
MultiplierStringOverflow(String),
|
MultiplierStringOverflow(String),
|
||||||
|
#[error("conv=block or conv=unblock specified without cbs=N")]
|
||||||
BlockUnblockWithoutCBS,
|
BlockUnblockWithoutCBS,
|
||||||
|
#[error("status=LEVEL not recognized -> {0}")]
|
||||||
StatusLevelNotRecognized(String),
|
StatusLevelNotRecognized(String),
|
||||||
|
#[error("feature not implemented on this system -> {0}")]
|
||||||
Unimplemented(String),
|
Unimplemented(String),
|
||||||
|
#[error("{0}=N cannot fit into memory")]
|
||||||
BsOutOfRange(String),
|
BsOutOfRange(String),
|
||||||
|
#[error("invalid number: ‘{0}’")]
|
||||||
InvalidNumber(String),
|
InvalidNumber(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -396,69 +410,6 @@ impl Parser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Display for ParseError {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
||||||
match self {
|
|
||||||
Self::UnrecognizedOperand(arg) => {
|
|
||||||
write!(f, "Unrecognized operand '{arg}'")
|
|
||||||
}
|
|
||||||
Self::MultipleFmtTable => {
|
|
||||||
write!(
|
|
||||||
f,
|
|
||||||
"Only one of conv=ascii conv=ebcdic or conv=ibm may be specified"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
Self::MultipleUCaseLCase => {
|
|
||||||
write!(f, "Only one of conv=lcase or conv=ucase may be specified")
|
|
||||||
}
|
|
||||||
Self::MultipleBlockUnblock => {
|
|
||||||
write!(f, "Only one of conv=block or conv=unblock may be specified")
|
|
||||||
}
|
|
||||||
Self::MultipleExclNoCreate => {
|
|
||||||
write!(f, "Only one ov conv=excl or conv=nocreat may be specified")
|
|
||||||
}
|
|
||||||
Self::FlagNoMatch(arg) => {
|
|
||||||
// Additional message about 'dd --help' is displayed only in this situation.
|
|
||||||
write!(
|
|
||||||
f,
|
|
||||||
"invalid input flag: ‘{}’\nTry '{} --help' for more information.",
|
|
||||||
arg,
|
|
||||||
uucore::execution_phrase()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
Self::ConvFlagNoMatch(arg) => {
|
|
||||||
write!(f, "Unrecognized conv=CONV -> {arg}")
|
|
||||||
}
|
|
||||||
Self::MultiplierStringParseFailure(arg) => {
|
|
||||||
write!(f, "invalid number: ‘{arg}’")
|
|
||||||
}
|
|
||||||
Self::MultiplierStringOverflow(arg) => {
|
|
||||||
write!(
|
|
||||||
f,
|
|
||||||
"Multiplier string would overflow on current system -> {arg}"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
Self::BlockUnblockWithoutCBS => {
|
|
||||||
write!(f, "conv=block or conv=unblock specified without cbs=N")
|
|
||||||
}
|
|
||||||
Self::StatusLevelNotRecognized(arg) => {
|
|
||||||
write!(f, "status=LEVEL not recognized -> {arg}")
|
|
||||||
}
|
|
||||||
Self::BsOutOfRange(arg) => {
|
|
||||||
write!(f, "{arg}=N cannot fit into memory")
|
|
||||||
}
|
|
||||||
Self::Unimplemented(arg) => {
|
|
||||||
write!(f, "feature not implemented on this system -> {arg}")
|
|
||||||
}
|
|
||||||
Self::InvalidNumber(arg) => {
|
|
||||||
write!(f, "invalid number: ‘{arg}’")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Error for ParseError {}
|
|
||||||
|
|
||||||
impl UError for ParseError {
|
impl UError for ParseError {
|
||||||
fn code(&self) -> i32 {
|
fn code(&self) -> i32 {
|
||||||
1
|
1
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue