melib/error: impl From<io::ErrorKind> for ErrorKind
Tests / Test on ${{ matrix.build }} (linux-amd64, ubuntu-latest, stable, x86_64-unknown-linux-gnu) (push) Successful in 7m43s
Details
Tests / Test on ${{ matrix.build }} (linux-amd64, ubuntu-latest, stable, x86_64-unknown-linux-gnu) (push) Successful in 7m43s
Details
We inspect errors in the frontend to check for network errors. If the network error comes from std::io, this would get converted to an Error with description "timed out", kind OSError, and source the actual networking error. This commit converts network std::io::ErrorKinds into appropriate native ErrorKinds. Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>feature/async-job-delay-wait
parent
dc2b00442b
commit
b3858de2f4
|
@ -107,7 +107,7 @@ mod dbus {
|
|||
Some(NotificationType::Error(melib::ErrorKind::Network(_))) => {
|
||||
notification.icon("network-error");
|
||||
}
|
||||
Some(NotificationType::Error(melib::ErrorKind::Timeout)) => {
|
||||
Some(NotificationType::Error(melib::ErrorKind::TimedOut)) => {
|
||||
notification.icon("network-offline");
|
||||
}
|
||||
_ => {}
|
||||
|
|
|
@ -332,7 +332,7 @@ pub enum ErrorKind {
|
|||
ProtocolNotSupported,
|
||||
Bug,
|
||||
Network(NetworkErrorKind),
|
||||
Timeout,
|
||||
TimedOut,
|
||||
OSError,
|
||||
NotImplemented,
|
||||
NotSupported,
|
||||
|
@ -353,7 +353,7 @@ impl std::fmt::Display for ErrorKind {
|
|||
Self::ProtocolError => "Protocol error",
|
||||
Self::ProtocolNotSupported =>
|
||||
"Protocol is not supported. It could be the wrong type or version.",
|
||||
Self::Timeout => "Timeout",
|
||||
Self::TimedOut => "Timed Out",
|
||||
Self::OSError => "OS Error",
|
||||
Self::Configuration => "Configuration",
|
||||
Self::NotImplemented => "Not implemented",
|
||||
|
@ -385,7 +385,7 @@ impl ErrorKind {
|
|||
is_variant! { is_oserror, OSError }
|
||||
is_variant! { is_protocol_error, ProtocolError }
|
||||
is_variant! { is_protocol_not_supported, ProtocolNotSupported }
|
||||
is_variant! { is_timeout, Timeout }
|
||||
is_variant! { is_timeout, TimedOut }
|
||||
is_variant! { is_value_error, ValueError }
|
||||
}
|
||||
|
||||
|
@ -534,13 +534,27 @@ impl std::error::Error for Error {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<io::ErrorKind> for ErrorKind {
|
||||
fn from(kind: io::ErrorKind) -> Self {
|
||||
match kind {
|
||||
io::ErrorKind::ConnectionRefused
|
||||
| io::ErrorKind::ConnectionReset
|
||||
| io::ErrorKind::ConnectionAborted
|
||||
| io::ErrorKind::NotConnected => Self::Network(NetworkErrorKind::ConnectionFailed),
|
||||
io::ErrorKind::TimedOut => Self::TimedOut,
|
||||
_ => Self::OSError,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<io::Error> for Error {
|
||||
#[inline]
|
||||
fn from(kind: io::Error) -> Self {
|
||||
Self::new(kind.to_string())
|
||||
.set_details(kind.kind().to_string())
|
||||
.set_source(Some(Arc::new(kind)))
|
||||
.set_kind(ErrorKind::OSError)
|
||||
fn from(err: io::Error) -> Self {
|
||||
let kind = err.kind().into();
|
||||
Self::new(err.to_string())
|
||||
.set_details(err.kind().to_string())
|
||||
.set_source(Some(Arc::new(err)))
|
||||
.set_kind(kind)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -651,7 +651,7 @@ impl ImapConnection {
|
|||
"Connection timed out after {} seconds",
|
||||
IMAP_PROTOCOL_TIMEOUT.as_secs()
|
||||
))
|
||||
.set_kind(ErrorKind::Timeout);
|
||||
.set_kind(ErrorKind::TimedOut);
|
||||
*status = Err(err.clone());
|
||||
self.stream = Err(err);
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ pub async fn timeout<O>(
|
|||
Either::Left((out, _)) => Ok(out),
|
||||
Either::Right(_) => {
|
||||
Err(crate::error::Error::new("Timed out.")
|
||||
.set_kind(crate::error::ErrorKind::Timeout))
|
||||
.set_kind(crate::error::ErrorKind::TimedOut))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue