mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 12:07:46 +00:00
uucore: fall back to stripping the error message for unexpected io error kinds
Rust recently added new error kinds, which causes tests to fail on beta/nightly. However, we can't match for these new error kinds because they are marked as unstable. As a workaround we call `.to_string()` on the original error and strip the ` (os error XX)` bit. The downside of this is that the error messages are not capitalized.
This commit is contained in:
parent
1e78a40e20
commit
b82401e744
1 changed files with 31 additions and 27 deletions
|
@ -368,7 +368,7 @@ impl UIoError {
|
||||||
pub fn new<S: Into<String>>(kind: std::io::ErrorKind, context: S) -> Box<dyn UError> {
|
pub fn new<S: Into<String>>(kind: std::io::ErrorKind, context: S) -> Box<dyn UError> {
|
||||||
Box::new(Self {
|
Box::new(Self {
|
||||||
context: context.into(),
|
context: context.into(),
|
||||||
inner: std::io::Error::new(kind, ""),
|
inner: kind.into(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -380,11 +380,9 @@ impl Error for UIoError {}
|
||||||
impl Display for UIoError {
|
impl Display for UIoError {
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), std::fmt::Error> {
|
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), std::fmt::Error> {
|
||||||
use std::io::ErrorKind::*;
|
use std::io::ErrorKind::*;
|
||||||
write!(
|
|
||||||
f,
|
let message;
|
||||||
"{}: {}",
|
let message = match self.inner.kind() {
|
||||||
self.context,
|
|
||||||
match self.inner.kind() {
|
|
||||||
NotFound => "No such file or directory",
|
NotFound => "No such file or directory",
|
||||||
PermissionDenied => "Permission denied",
|
PermissionDenied => "Permission denied",
|
||||||
ConnectionRefused => "Connection refused",
|
ConnectionRefused => "Connection refused",
|
||||||
|
@ -403,9 +401,15 @@ impl Display for UIoError {
|
||||||
Interrupted => "Interrupted",
|
Interrupted => "Interrupted",
|
||||||
Other => "Other",
|
Other => "Other",
|
||||||
UnexpectedEof => "Unexpected end of file",
|
UnexpectedEof => "Unexpected end of file",
|
||||||
_ => panic!("Unexpected io error: {}", self.inner),
|
_ => {
|
||||||
},
|
// TODO: using `strip_errno()` causes the error message
|
||||||
)
|
// to not be capitalized. When the new error variants (https://github.com/rust-lang/rust/issues/86442)
|
||||||
|
// are stabilized, we should add them to the match statement.
|
||||||
|
message = strip_errno(&self.inner);
|
||||||
|
&message
|
||||||
|
}
|
||||||
|
};
|
||||||
|
write!(f, "{}: {}", self.context, message,)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue