error: wrap io::Error in Arc for clone
`ProtoErrorKind` is `Clone`, but the `Io` variant holding `io:Error` runs into trouble with this: since the error can't be cloned we have to reconstruct it and this is a lossy process: resulting in a "simple" `io::Error` that only holds the error type from the parent it was cloned from. This loses important details like the underlying error source/message. This commit changes `ProtoErrorKind::Io` to hold `Arc<io::Error>>` instead. This makes implementing `Clone` trivial - we clone the arc - and no error information is lost.
This commit is contained in:
parent
6c2a1e2c23
commit
2e84c1184b
@ -10,6 +10,7 @@
|
|||||||
#![deny(missing_docs)]
|
#![deny(missing_docs)]
|
||||||
|
|
||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
|
use std::sync::Arc;
|
||||||
use std::{fmt, io, sync};
|
use std::{fmt, io, sync};
|
||||||
|
|
||||||
#[cfg(feature = "backtrace")]
|
#[cfg(feature = "backtrace")]
|
||||||
@ -233,7 +234,7 @@ pub enum ProtoErrorKind {
|
|||||||
// foreign
|
// foreign
|
||||||
/// An error got returned from IO
|
/// An error got returned from IO
|
||||||
#[error("io error: {0}")]
|
#[error("io error: {0}")]
|
||||||
Io(io::Error),
|
Io(Arc<io::Error>),
|
||||||
|
|
||||||
/// Any sync poised error
|
/// Any sync poised error
|
||||||
#[error("lock poisoned error")]
|
#[error("lock poisoned error")]
|
||||||
@ -554,7 +555,7 @@ impl From<io::Error> for ProtoErrorKind {
|
|||||||
fn from(e: io::Error) -> Self {
|
fn from(e: io::Error) -> Self {
|
||||||
match e.kind() {
|
match e.kind() {
|
||||||
io::ErrorKind::TimedOut => Self::Timeout,
|
io::ErrorKind::TimedOut => Self::Timeout,
|
||||||
_ => Self::Io(e),
|
_ => Self::Io(e.into()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -641,11 +642,7 @@ impl Clone for ProtoErrorKind {
|
|||||||
UnrecognizedLabelCode(value) => UnrecognizedLabelCode(value),
|
UnrecognizedLabelCode(value) => UnrecognizedLabelCode(value),
|
||||||
UnrecognizedNsec3Flags(flags) => UnrecognizedNsec3Flags(flags),
|
UnrecognizedNsec3Flags(flags) => UnrecognizedNsec3Flags(flags),
|
||||||
UnrecognizedCsyncFlags(flags) => UnrecognizedCsyncFlags(flags),
|
UnrecognizedCsyncFlags(flags) => UnrecognizedCsyncFlags(flags),
|
||||||
Io(ref e) => Io(if let Some(raw) = e.raw_os_error() {
|
Io(ref e) => Io(e.clone()),
|
||||||
io::Error::from_raw_os_error(raw)
|
|
||||||
} else {
|
|
||||||
io::Error::from(e.kind())
|
|
||||||
}),
|
|
||||||
Poisoned => Poisoned,
|
Poisoned => Poisoned,
|
||||||
Ring(ref _e) => Ring(Unspecified),
|
Ring(ref _e) => Ring(Unspecified),
|
||||||
SSL(ref e) => Msg(format!("there was an SSL error: {e}")),
|
SSL(ref e) => Msg(format!("there was an SSL error: {e}")),
|
||||||
|
Loading…
Reference in New Issue
Block a user