Skip to content

Commit a5a9f7d

Browse files
authored
pr: migrate from quick-error to thiserror (#7919)
* remove quick-error from pr * fix windows compilation, Cargo.toml
1 parent 5e11842 commit a5a9f7d

File tree

3 files changed

+21
-36
lines changed

3 files changed

+21
-36
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/uu/pr/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ path = "src/pr.rs"
2020
[dependencies]
2121
clap = { workspace = true }
2222
uucore = { workspace = true, features = ["entries"] }
23-
quick-error = { workspace = true }
2423
itertools = { workspace = true }
2524
regex = { workspace = true }
2625
chrono = { workspace = true }
26+
thiserror = { workspace = true }
2727

2828
[[bin]]
2929
name = "pr"

src/uu/pr/src/pr.rs

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@
99
use chrono::{DateTime, Local};
1010
use clap::{Arg, ArgAction, ArgMatches, Command};
1111
use itertools::Itertools;
12-
use quick_error::ResultExt;
1312
use regex::Regex;
1413
use std::fs::{File, metadata};
1514
use std::io::{BufRead, BufReader, Lines, Read, Write, stdin, stdout};
1615
#[cfg(unix)]
1716
use std::os::unix::fs::FileTypeExt;
17+
use thiserror::Error;
1818

19-
use quick_error::quick_error;
2019
use uucore::display::Quotable;
2120
use uucore::error::UResult;
2221
use uucore::{format_usage, help_about, help_section, help_usage};
@@ -134,35 +133,21 @@ impl From<std::io::Error> for PrError {
134133
}
135134
}
136135

137-
quick_error! {
138-
#[derive(Debug)]
139-
enum PrError {
140-
Input(err: std::io::Error, path: String) {
141-
context(path: &'a str, err: std::io::Error) -> (err, path.to_owned())
142-
display("pr: Reading from input {path} gave error")
143-
source(err)
144-
}
145-
146-
UnknownFiletype(path: String) {
147-
display("pr: {path}: unknown filetype")
148-
}
149-
150-
EncounteredErrors(msg: String) {
151-
display("pr: {msg}")
152-
}
153-
154-
IsDirectory(path: String) {
155-
display("pr: {path}: Is a directory")
156-
}
157-
158-
IsSocket(path: String) {
159-
display("pr: cannot open {path}, Operation not supported on socket")
160-
}
161-
162-
NotExists(path: String) {
163-
display("pr: cannot open {path}, No such file or directory")
164-
}
165-
}
136+
#[derive(Debug, Error)]
137+
enum PrError {
138+
#[error("pr: Reading from input {1} gave error")]
139+
Input(std::io::Error, String),
140+
#[error("pr: {0}: unknown filetype")]
141+
UnknownFiletype(String),
142+
#[error("pr: {0}")]
143+
EncounteredErrors(String),
144+
#[error("pr: {0}: Is a directory")]
145+
IsDirectory(String),
146+
#[cfg(not(windows))]
147+
#[error("pr: cannot open {0}, Operation not supported on socket")]
148+
IsSocket(String),
149+
#[error("pr: cannot open {0}, No such file or directory")]
150+
NotExists(String),
166151
}
167152

168153
pub fn uu_app() -> Command {
@@ -795,9 +780,9 @@ fn open(path: &str) -> Result<Box<dyn Read>, PrError> {
795780
#[cfg(unix)]
796781
ft if ft.is_socket() => Err(PrError::IsSocket(path_string)),
797782
ft if ft.is_dir() => Err(PrError::IsDirectory(path_string)),
798-
ft if ft.is_file() || ft.is_symlink() => {
799-
Ok(Box::new(File::open(path).context(path)?) as Box<dyn Read>)
800-
}
783+
ft if ft.is_file() || ft.is_symlink() => Ok(Box::new(
784+
File::open(path).map_err(|e| PrError::Input(e, path.to_string()))?,
785+
) as Box<dyn Read>),
801786
_ => Err(PrError::UnknownFiletype(path_string)),
802787
}
803788
})

0 commit comments

Comments
 (0)