Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/uu/dd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ clap = { workspace = true }
gcd = { workspace = true }
libc = { workspace = true }
uucore = { workspace = true, features = ["format", "quoting-style"] }
thiserror = { workspace = true }

[target.'cfg(any(target_os = "linux", target_os = "android"))'.dependencies]
signal-hook = { workspace = true }
Expand Down
81 changes: 16 additions & 65 deletions src/uu/dd/src/parseargs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,42 @@ mod unit_tests;

use super::{ConversionMode, IConvFlags, IFlags, Num, OConvFlags, OFlags, Settings, StatusLevel};
use crate::conversion_tables::ConversionTable;
use std::error::Error;
use thiserror::Error;
use uucore::display::Quotable;
use uucore::error::UError;
use uucore::parse_size::{ParseSizeError, Parser as SizeParser};
use uucore::show_warning;

/// Parser Errors describe errors with parser input
#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq, Error)]
pub enum ParseError {
#[error("Unrecognized operand '{0}'")]
UnrecognizedOperand(String),
#[error("Only one of conv=ascii conv=ebcdic or conv=ibm may be specified")]
MultipleFmtTable,
#[error("Only one of conv=lcase or conv=ucase may be specified")]
MultipleUCaseLCase,
#[error("Only one of conv=block or conv=unblock may be specified")]
MultipleBlockUnblock,
#[error("Only one ov conv=excl or conv=nocreat may be specified")]
MultipleExclNoCreate,
#[error("invalid input flag: ‘{}’\nTry '{} --help' for more information.", .0, uucore::execution_phrase())]
FlagNoMatch(String),
#[error("Unrecognized conv=CONV -> {0}")]
ConvFlagNoMatch(String),
#[error("invalid number: ‘{0}’")]
MultiplierStringParseFailure(String),
#[error("Multiplier string would overflow on current system -> {0}")]
MultiplierStringOverflow(String),
#[error("conv=block or conv=unblock specified without cbs=N")]
BlockUnblockWithoutCBS,
#[error("status=LEVEL not recognized -> {0}")]
StatusLevelNotRecognized(String),
#[error("feature not implemented on this system -> {0}")]
Unimplemented(String),
#[error("{0}=N cannot fit into memory")]
BsOutOfRange(String),
#[error("invalid number: ‘{0}’")]
InvalidNumber(String),
}

Expand Down Expand Up @@ -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 {
fn code(&self) -> i32 {
1
Expand Down
1 change: 1 addition & 0 deletions src/uu/expand/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ path = "src/expand.rs"
clap = { workspace = true }
unicode-width = { workspace = true }
uucore = { workspace = true }
thiserror = { workspace = true }

[[bin]]
name = "expand"
Expand Down
36 changes: 8 additions & 28 deletions src/uu/expand/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
// spell-checker:ignore (ToDO) ctype cwidth iflag nbytes nspaces nums tspaces uflag Preprocess

use clap::{Arg, ArgAction, ArgMatches, Command};
use std::error::Error;
use std::ffi::OsString;
use std::fmt;
use std::fs::File;
use std::io::{BufRead, BufReader, BufWriter, Read, Write, stdin, stdout};
use std::num::IntErrorKind;
use std::path::Path;
use std::str::from_utf8;
use thiserror::Error;
use unicode_width::UnicodeWidthChar;
use uucore::display::Quotable;
use uucore::error::{FromIo, UError, UResult, set_exit_code};
Expand Down Expand Up @@ -61,43 +60,24 @@ fn is_digit_or_comma(c: char) -> bool {
}

/// Errors that can occur when parsing a `--tabs` argument.
#[derive(Debug)]
#[derive(Debug, Error)]
enum ParseError {
#[error("tab size contains invalid character(s): {}", .0.quote())]
InvalidCharacter(String),
#[error("{} specifier not at start of number: {}", .0.quote(), .1.quote())]
SpecifierNotAtStartOfNumber(String, String),
#[error("{} specifier only allowed with the last value", .0.quote())]
SpecifierOnlyAllowedWithLastValue(String),
#[error("tab size cannot be 0")]
TabSizeCannotBeZero,
#[error("tab stop is too large {}", .0.quote())]
TabSizeTooLarge(String),
#[error("tab sizes must be ascending")]
TabSizesMustBeAscending,
}

impl Error for ParseError {}
impl UError for ParseError {}

impl fmt::Display for ParseError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Self::InvalidCharacter(s) => {
write!(f, "tab size contains invalid character(s): {}", s.quote())
}
Self::SpecifierNotAtStartOfNumber(specifier, s) => write!(
f,
"{} specifier not at start of number: {}",
specifier.quote(),
s.quote(),
),
Self::SpecifierOnlyAllowedWithLastValue(specifier) => write!(
f,
"{} specifier only allowed with the last value",
specifier.quote()
),
Self::TabSizeCannotBeZero => write!(f, "tab size cannot be 0"),
Self::TabSizeTooLarge(s) => write!(f, "tab stop is too large {}", s.quote()),
Self::TabSizesMustBeAscending => write!(f, "tab sizes must be ascending"),
}
}
}

/// Parse a list of tabstops from a `--tabs` argument.
///
/// This function returns both the vector of numbers appearing in the
Expand Down
1 change: 1 addition & 0 deletions src/uu/numfmt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ path = "src/numfmt.rs"
[dependencies]
clap = { workspace = true }
uucore = { workspace = true, features = ["ranges"] }
thiserror = { workspace = true }

[[bin]]
name = "numfmt"
Expand Down
21 changes: 4 additions & 17 deletions src/uu/numfmt/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

use std::{
error::Error,
fmt::{Debug, Display},
};
use std::fmt::Debug;
use thiserror::Error;
use uucore::error::UError;

#[derive(Debug)]
#[derive(Debug, Error)]
#[error("{0}")]
pub enum NumfmtError {
IoError(String),
IllegalArgument(String),
Expand All @@ -25,15 +24,3 @@ impl UError for NumfmtError {
}
}
}

impl Error for NumfmtError {}

impl Display for NumfmtError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::IoError(s) | Self::IllegalArgument(s) | Self::FormattingError(s) => {
write!(f, "{s}")
}
}
}
}
1 change: 1 addition & 0 deletions src/uu/ptx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ path = "src/ptx.rs"
clap = { workspace = true }
regex = { workspace = true }
uucore = { workspace = true }
thiserror = { workspace = true }

[[bin]]
name = "ptx"
Expand Down
22 changes: 6 additions & 16 deletions src/uu/ptx/src/ptx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ use clap::{Arg, ArgAction, Command};
use regex::Regex;
use std::cmp;
use std::collections::{BTreeSet, HashMap, HashSet};
use std::error::Error;
use std::fmt::{Display, Formatter, Write as FmtWrite};
use std::fmt::Write as FmtWrite;
use std::fs::File;
use std::io::{BufRead, BufReader, BufWriter, Read, Write, stdin, stdout};
use std::num::ParseIntError;
use thiserror::Error;
use uucore::display::Quotable;
use uucore::error::{FromIo, UError, UResult, UUsageError};
use uucore::{format_usage, help_about, help_usage};
Expand Down Expand Up @@ -194,28 +194,18 @@ struct WordRef {
filename: String,
}

#[derive(Debug)]
#[derive(Debug, Error)]
enum PtxError {
#[error("There is no dumb format with GNU extensions disabled")]
DumbFormat,
#[error("{0} not implemented yet")]
NotImplemented(&'static str),
#[error("{0}")]
ParseError(ParseIntError),
}

impl Error for PtxError {}
impl UError for PtxError {}

impl Display for PtxError {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
match self {
Self::DumbFormat => {
write!(f, "There is no dumb format with GNU extensions disabled")
}
Self::NotImplemented(s) => write!(f, "{s} not implemented yet"),
Self::ParseError(e) => e.fmt(f),
}
}
}

fn get_config(matches: &clap::ArgMatches) -> UResult<Config> {
let mut config = Config::default();
let err_msg = "parsing options failed";
Expand Down
1 change: 1 addition & 0 deletions src/uu/split/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ path = "src/split.rs"
clap = { workspace = true }
memchr = { workspace = true }
uucore = { workspace = true, features = ["fs"] }
thiserror = { workspace = true }

[[bin]]
name = "split"
Expand Down
Loading
Loading