1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-30 12:37:49 +00:00

tac: move to thiserror

This commit is contained in:
Solomon Victorino 2025-03-22 18:18:15 -06:00 committed by Sylvestre Ledru
parent 9db51ec828
commit 899c118f3f
3 changed files with 9 additions and 23 deletions

1
Cargo.lock generated
View file

@ -3297,6 +3297,7 @@ dependencies = [
"memchr", "memchr",
"memmap2", "memmap2",
"regex", "regex",
"thiserror 2.0.12",
"uucore", "uucore",
] ]

View file

@ -24,6 +24,7 @@ memmap2 = { workspace = true }
regex = { workspace = true } regex = { workspace = true }
clap = { workspace = true } clap = { workspace = true }
uucore = { workspace = true } uucore = { workspace = true }
thiserror = { workspace = true }
[[bin]] [[bin]]
name = "tac" name = "tac"

View file

@ -3,33 +3,37 @@
// For the full copyright and license information, please view the LICENSE // For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code. // file that was distributed with this source code.
//! Errors returned by tac during processing of a file. //! Errors returned by tac during processing of a file.
use std::error::Error; use thiserror::Error;
use std::fmt::Display;
use uucore::display::Quotable; use uucore::display::Quotable;
use uucore::error::UError; use uucore::error::UError;
#[derive(Debug)] #[derive(Debug, Error)]
pub enum TacError { pub enum TacError {
/// A regular expression given by the user is invalid. /// A regular expression given by the user is invalid.
#[error("invalid regular expression: {0}")]
InvalidRegex(regex::Error), InvalidRegex(regex::Error),
/// An argument to tac is invalid. /// An argument to tac is invalid.
#[error("{}: read error: Invalid argument", _0.maybe_quote())]
InvalidArgument(String), InvalidArgument(String),
/// The specified file is not found on the filesystem. /// The specified file is not found on the filesystem.
#[error("failed to open {} for reading: No such file or directory", _0.quote())]
FileNotFound(String), FileNotFound(String),
/// An error reading the contents of a file or stdin. /// An error reading the contents of a file or stdin.
/// ///
/// The parameters are the name of the file and the underlying /// The parameters are the name of the file and the underlying
/// [`std::io::Error`] that caused this error. /// [`std::io::Error`] that caused this error.
#[error("failed to read from {0}: {1}")]
ReadError(String, std::io::Error), ReadError(String, std::io::Error),
/// An error writing the (reversed) contents of a file or stdin. /// An error writing the (reversed) contents of a file or stdin.
/// ///
/// The parameter is the underlying [`std::io::Error`] that caused /// The parameter is the underlying [`std::io::Error`] that caused
/// this error. /// this error.
#[error("failed to write to stdout: {0}")]
WriteError(std::io::Error), WriteError(std::io::Error),
} }
@ -38,23 +42,3 @@ impl UError for TacError {
1 1
} }
} }
impl Error for TacError {}
impl Display for TacError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::InvalidRegex(e) => write!(f, "invalid regular expression: {e}"),
Self::InvalidArgument(s) => {
write!(f, "{}: read error: Invalid argument", s.maybe_quote())
}
Self::FileNotFound(s) => write!(
f,
"failed to open {} for reading: No such file or directory",
s.quote()
),
Self::ReadError(s, e) => write!(f, "failed to read from {s}: {e}"),
Self::WriteError(e) => write!(f, "failed to write to stdout: {e}"),
}
}
}