|
9 | 9 | use chrono::{DateTime, Local}; |
10 | 10 | use clap::{Arg, ArgAction, ArgMatches, Command}; |
11 | 11 | use itertools::Itertools; |
12 | | -use quick_error::ResultExt; |
13 | 12 | use regex::Regex; |
14 | 13 | use std::fs::{File, metadata}; |
15 | 14 | use std::io::{BufRead, BufReader, Lines, Read, Write, stdin, stdout}; |
16 | 15 | #[cfg(unix)] |
17 | 16 | use std::os::unix::fs::FileTypeExt; |
| 17 | +use thiserror::Error; |
18 | 18 |
|
19 | | -use quick_error::quick_error; |
20 | 19 | use uucore::display::Quotable; |
21 | 20 | use uucore::error::UResult; |
22 | 21 | use uucore::{format_usage, help_about, help_section, help_usage}; |
@@ -134,35 +133,21 @@ impl From<std::io::Error> for PrError { |
134 | 133 | } |
135 | 134 | } |
136 | 135 |
|
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), |
166 | 151 | } |
167 | 152 |
|
168 | 153 | pub fn uu_app() -> Command { |
@@ -795,9 +780,9 @@ fn open(path: &str) -> Result<Box<dyn Read>, PrError> { |
795 | 780 | #[cfg(unix)] |
796 | 781 | ft if ft.is_socket() => Err(PrError::IsSocket(path_string)), |
797 | 782 | 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>), |
801 | 786 | _ => Err(PrError::UnknownFiletype(path_string)), |
802 | 787 | } |
803 | 788 | }) |
|
0 commit comments