1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-27 11:07:44 +00:00

pr: migrate from quick-error to thiserror (#7919)

* remove quick-error from pr

* fix windows compilation, Cargo.toml
This commit is contained in:
Jeremy Smart 2025-05-15 03:19:46 -04:00 committed by GitHub
parent 5e11842428
commit a5a9f7d44d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 21 additions and 36 deletions

2
Cargo.lock generated
View file

@ -3138,8 +3138,8 @@ dependencies = [
"chrono", "chrono",
"clap", "clap",
"itertools 0.14.0", "itertools 0.14.0",
"quick-error",
"regex", "regex",
"thiserror 2.0.12",
"uucore", "uucore",
] ]

View file

@ -20,10 +20,10 @@ path = "src/pr.rs"
[dependencies] [dependencies]
clap = { workspace = true } clap = { workspace = true }
uucore = { workspace = true, features = ["entries"] } uucore = { workspace = true, features = ["entries"] }
quick-error = { workspace = true }
itertools = { workspace = true } itertools = { workspace = true }
regex = { workspace = true } regex = { workspace = true }
chrono = { workspace = true } chrono = { workspace = true }
thiserror = { workspace = true }
[[bin]] [[bin]]
name = "pr" name = "pr"

View file

@ -9,14 +9,13 @@
use chrono::{DateTime, Local}; use chrono::{DateTime, Local};
use clap::{Arg, ArgAction, ArgMatches, Command}; use clap::{Arg, ArgAction, ArgMatches, Command};
use itertools::Itertools; use itertools::Itertools;
use quick_error::ResultExt;
use regex::Regex; use regex::Regex;
use std::fs::{File, metadata}; use std::fs::{File, metadata};
use std::io::{BufRead, BufReader, Lines, Read, Write, stdin, stdout}; use std::io::{BufRead, BufReader, Lines, Read, Write, stdin, stdout};
#[cfg(unix)] #[cfg(unix)]
use std::os::unix::fs::FileTypeExt; use std::os::unix::fs::FileTypeExt;
use thiserror::Error;
use quick_error::quick_error;
use uucore::display::Quotable; use uucore::display::Quotable;
use uucore::error::UResult; use uucore::error::UResult;
use uucore::{format_usage, help_about, help_section, help_usage}; use uucore::{format_usage, help_about, help_section, help_usage};
@ -134,35 +133,21 @@ impl From<std::io::Error> for PrError {
} }
} }
quick_error! { #[derive(Debug, Error)]
#[derive(Debug)] enum PrError {
enum PrError { #[error("pr: Reading from input {1} gave error")]
Input(err: std::io::Error, path: String) { Input(std::io::Error, String),
context(path: &'a str, err: std::io::Error) -> (err, path.to_owned()) #[error("pr: {0}: unknown filetype")]
display("pr: Reading from input {path} gave error") UnknownFiletype(String),
source(err) #[error("pr: {0}")]
} EncounteredErrors(String),
#[error("pr: {0}: Is a directory")]
UnknownFiletype(path: String) { IsDirectory(String),
display("pr: {path}: unknown filetype") #[cfg(not(windows))]
} #[error("pr: cannot open {0}, Operation not supported on socket")]
IsSocket(String),
EncounteredErrors(msg: String) { #[error("pr: cannot open {0}, No such file or directory")]
display("pr: {msg}") NotExists(String),
}
IsDirectory(path: String) {
display("pr: {path}: Is a directory")
}
IsSocket(path: String) {
display("pr: cannot open {path}, Operation not supported on socket")
}
NotExists(path: String) {
display("pr: cannot open {path}, No such file or directory")
}
}
} }
pub fn uu_app() -> Command { pub fn uu_app() -> Command {
@ -795,9 +780,9 @@ fn open(path: &str) -> Result<Box<dyn Read>, PrError> {
#[cfg(unix)] #[cfg(unix)]
ft if ft.is_socket() => Err(PrError::IsSocket(path_string)), ft if ft.is_socket() => Err(PrError::IsSocket(path_string)),
ft if ft.is_dir() => Err(PrError::IsDirectory(path_string)), ft if ft.is_dir() => Err(PrError::IsDirectory(path_string)),
ft if ft.is_file() || ft.is_symlink() => { ft if ft.is_file() || ft.is_symlink() => Ok(Box::new(
Ok(Box::new(File::open(path).context(path)?) as Box<dyn Read>) File::open(path).map_err(|e| PrError::Input(e, path.to_string()))?,
} ) as Box<dyn Read>),
_ => Err(PrError::UnknownFiletype(path_string)), _ => Err(PrError::UnknownFiletype(path_string)),
} }
}) })