mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-31 04:57:45 +00:00
seq: move to thiserror
This commit is contained in:
parent
740cea7a46
commit
70f3429102
2 changed files with 15 additions and 25 deletions
|
@ -22,6 +22,7 @@ bigdecimal = { workspace = true }
|
||||||
clap = { workspace = true }
|
clap = { workspace = true }
|
||||||
num-bigint = { workspace = true }
|
num-bigint = { workspace = true }
|
||||||
num-traits = { workspace = true }
|
num-traits = { workspace = true }
|
||||||
|
thiserror = { workspace = true }
|
||||||
uucore = { workspace = true, features = ["format", "quoting-style"] }
|
uucore = { workspace = true, features = ["format", "quoting-style"] }
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
|
|
|
@ -4,32 +4,40 @@
|
||||||
// file that was distributed with this source code.
|
// file that was distributed with this source code.
|
||||||
// spell-checker:ignore numberparse
|
// spell-checker:ignore numberparse
|
||||||
//! Errors returned by seq.
|
//! Errors returned by seq.
|
||||||
use std::error::Error;
|
use crate::numberparse::ParseNumberError;
|
||||||
use std::fmt::Display;
|
use thiserror::Error;
|
||||||
|
|
||||||
use uucore::display::Quotable;
|
use uucore::display::Quotable;
|
||||||
use uucore::error::UError;
|
use uucore::error::UError;
|
||||||
|
|
||||||
use crate::numberparse::ParseNumberError;
|
#[derive(Debug, Error)]
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub enum SeqError {
|
pub enum SeqError {
|
||||||
/// An error parsing the input arguments.
|
/// An error parsing the input arguments.
|
||||||
///
|
///
|
||||||
/// The parameters are the [`String`] argument as read from the
|
/// The parameters are the [`String`] argument as read from the
|
||||||
/// command line and the underlying parsing error itself.
|
/// command line and the underlying parsing error itself.
|
||||||
|
#[error("invalid {} argument: {}", parse_error_type(.1), .0.quote())]
|
||||||
ParseError(String, ParseNumberError),
|
ParseError(String, ParseNumberError),
|
||||||
|
|
||||||
/// The increment argument was zero, which is not allowed.
|
/// The increment argument was zero, which is not allowed.
|
||||||
///
|
///
|
||||||
/// The parameter is the increment argument as a [`String`] as read
|
/// The parameter is the increment argument as a [`String`] as read
|
||||||
/// from the command line.
|
/// from the command line.
|
||||||
|
#[error("invalid Zero increment value: {}", .0.quote())]
|
||||||
ZeroIncrement(String),
|
ZeroIncrement(String),
|
||||||
|
|
||||||
/// No arguments were passed to this function, 1 or more is required
|
/// No arguments were passed to this function, 1 or more is required
|
||||||
|
#[error("missing operand")]
|
||||||
NoArguments,
|
NoArguments,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn parse_error_type(e: &ParseNumberError) -> &'static str {
|
||||||
|
match e {
|
||||||
|
ParseNumberError::Float => "floating point",
|
||||||
|
ParseNumberError::Nan => "'not-a-number'",
|
||||||
|
ParseNumberError::Hex => "hexadecimal",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl UError for SeqError {
|
impl UError for SeqError {
|
||||||
/// Always return 1.
|
/// Always return 1.
|
||||||
fn code(&self) -> i32 {
|
fn code(&self) -> i32 {
|
||||||
|
@ -40,22 +48,3 @@ impl UError for SeqError {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Error for SeqError {}
|
|
||||||
|
|
||||||
impl Display for SeqError {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
||||||
match self {
|
|
||||||
Self::ParseError(s, e) => {
|
|
||||||
let error_type = match e {
|
|
||||||
ParseNumberError::Float => "floating point",
|
|
||||||
ParseNumberError::Nan => "'not-a-number'",
|
|
||||||
ParseNumberError::Hex => "hexadecimal",
|
|
||||||
};
|
|
||||||
write!(f, "invalid {error_type} argument: {}", s.quote())
|
|
||||||
}
|
|
||||||
Self::ZeroIncrement(s) => write!(f, "invalid Zero increment value: {}", s.quote()),
|
|
||||||
Self::NoArguments => write!(f, "missing operand"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue