|
|
@ -1,46 +1,41 @@
|
|
|
|
use crate::utils::VerboseErrorExt;
|
|
|
|
use crate::utils::Context;
|
|
|
|
|
|
|
|
|
|
|
|
/// Wrap `std::io::Error` with additional message
|
|
|
|
/// Wrap `std::io::Error` with additional message
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// *Note* Only active when `verbose-errors` feature is enabled for this crate!
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// Keeps the original error kind and stores the original I/O error as `source`.
|
|
|
|
/// Keeps the original error kind and stores the original I/O error as `source`.
|
|
|
|
impl<T> VerboseErrorExt for Result<T, std::io::Error> {
|
|
|
|
impl<T> Context for Result<T, std::io::Error> {
|
|
|
|
#[cfg(feature = "verbose-errors")]
|
|
|
|
fn context(self, message: impl Fn() -> String) -> Self {
|
|
|
|
fn verbose_context(self, message: impl Fn() -> String) -> Self {
|
|
|
|
self.map_err(|e| VerboseError::wrap(e, message()))
|
|
|
|
self.map_err(|e| verbose::Error::wrap(e, message()))
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(feature = "verbose-errors")]
|
|
|
|
use std::{error::Error as StdError, fmt, io};
|
|
|
|
mod verbose {
|
|
|
|
|
|
|
|
use std::{error::Error as StdError, fmt, io};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub(crate) struct Error {
|
|
|
|
pub(crate) struct VerboseError {
|
|
|
|
source: io::Error,
|
|
|
|
source: io::Error,
|
|
|
|
message: String,
|
|
|
|
message: String,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl Error {
|
|
|
|
impl VerboseError {
|
|
|
|
pub(crate) fn wrap(source: io::Error, message: impl Into<String>) -> io::Error {
|
|
|
|
pub(crate) fn wrap(source: io::Error, message: impl Into<String>) -> io::Error {
|
|
|
|
io::Error::new(
|
|
|
|
io::Error::new(
|
|
|
|
source.kind(),
|
|
|
|
source.kind(),
|
|
|
|
Error {
|
|
|
|
VerboseError {
|
|
|
|
source,
|
|
|
|
source,
|
|
|
|
message: message.into(),
|
|
|
|
message: message.into(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl fmt::Display for Error {
|
|
|
|
impl fmt::Display for VerboseError {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
write!(f, "{}", self.message)
|
|
|
|
write!(f, "{}", self.message)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl StdError for Error {
|
|
|
|
impl StdError for VerboseError {
|
|
|
|
fn description(&self) -> &str {
|
|
|
|
fn description(&self) -> &str {
|
|
|
|
self.source.description()
|
|
|
|
self.source.description()
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -48,5 +43,4 @@ mod verbose {
|
|
|
|
fn source(&self) -> Option<&(dyn StdError + 'static)> {
|
|
|
|
fn source(&self) -> Option<&(dyn StdError + 'static)> {
|
|
|
|
Some(&self.source)
|
|
|
|
Some(&self.source)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|