From 4cb23dd8405be164881812eacf1f3ac99ebcce4a Mon Sep 17 00:00:00 2001 From: Solomon Victorino Date: Sat, 22 Mar 2025 18:18:15 -0600 Subject: [PATCH] ptx: move to thiserror --- Cargo.lock | 1 + src/uu/ptx/Cargo.toml | 1 + src/uu/ptx/src/ptx.rs | 22 ++++++---------------- 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 445d7964e..70581006f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3102,6 +3102,7 @@ version = "0.0.30" dependencies = [ "clap", "regex", + "thiserror 2.0.12", "uucore", ] diff --git a/src/uu/ptx/Cargo.toml b/src/uu/ptx/Cargo.toml index 593aee1bd..d703a4f40 100644 --- a/src/uu/ptx/Cargo.toml +++ b/src/uu/ptx/Cargo.toml @@ -20,6 +20,7 @@ path = "src/ptx.rs" clap = { workspace = true } regex = { workspace = true } uucore = { workspace = true } +thiserror = { workspace = true } [[bin]] name = "ptx" diff --git a/src/uu/ptx/src/ptx.rs b/src/uu/ptx/src/ptx.rs index 12686474e..00d4f611e 100644 --- a/src/uu/ptx/src/ptx.rs +++ b/src/uu/ptx/src/ptx.rs @@ -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}; @@ -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 { let mut config = Config::default(); let err_msg = "parsing options failed";