1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-29 20:17:45 +00:00

ptx: move to thiserror

This commit is contained in:
Solomon Victorino 2025-03-22 18:18:15 -06:00 committed by Sylvestre Ledru
parent aea23408fd
commit 4cb23dd840
3 changed files with 8 additions and 16 deletions

1
Cargo.lock generated
View file

@ -3102,6 +3102,7 @@ version = "0.0.30"
dependencies = [
"clap",
"regex",
"thiserror 2.0.12",
"uucore",
]

View file

@ -20,6 +20,7 @@ path = "src/ptx.rs"
clap = { workspace = true }
regex = { workspace = true }
uucore = { workspace = true }
thiserror = { workspace = true }
[[bin]]
name = "ptx"

View file

@ -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<Config> {
let mut config = Config::default();
let err_msg = "parsing options failed";