pub struct Report { /* private fields */ }
Expand description
Core Diagnostic wrapper type.
eyre
Users
You can just replace use
s of eyre::Report
with miette::Report
.
Implementations
sourceimpl Report
impl Report
sourcepub fn new<E>(error: E) -> Selfwhere
E: Diagnostic + Send + Sync + 'static,
pub fn new<E>(error: E) -> Selfwhere
E: Diagnostic + Send + Sync + 'static,
Create a new error object from any error type.
The error type must be thread safe and 'static
, so that the Report
will be as well.
If the error type does not provide a backtrace, a backtrace will be created here to ensure that a backtrace exists.
sourcepub fn msg<M>(message: M) -> Selfwhere
M: Display + Debug + Send + Sync + 'static,
pub fn msg<M>(message: M) -> Selfwhere
M: Display + Debug + Send + Sync + 'static,
Create a new error object from a printable error message.
If the argument implements std::error::Error, prefer Report::new
instead which preserves the underlying error’s cause chain and
backtrace. If the argument may or may not implement std::error::Error
now or in the future, use miette!(err)
which handles either way
correctly.
Report::msg("...")
is equivalent to miette!("...")
but occasionally
convenient in places where a function is preferable over a macro, such
as iterator or stream combinators:
use futures::stream::{Stream, StreamExt, TryStreamExt};
use miette::{Report, Result};
async fn demo<S>(stream: S) -> Result<Vec<Output>>
where
S: Stream<Item = Input>,
{
stream
.then(ffi::do_some_work) // returns Result<Output, &str>
.map_err(Report::msg)
.try_collect()
.await
}
sourcepub fn wrap_err<D>(self, msg: D) -> Selfwhere
D: Display + Send + Sync + 'static,
pub fn wrap_err<D>(self, msg: D) -> Selfwhere
D: Display + Send + Sync + 'static,
Create a new error from an error message to wrap the existing error.
For attaching a higher level error message to a Result
as it is
propagated, the crate::WrapErr extension trait may be more
convenient than this function.
The primary reason to use error.wrap_err(...)
instead of
result.wrap_err(...)
via the WrapErr
trait would be if the
message needs to depend on some data held by the underlying error:
sourcepub fn context<D>(self, msg: D) -> Selfwhere
D: Display + Send + Sync + 'static,
pub fn context<D>(self, msg: D) -> Selfwhere
D: Display + Send + Sync + 'static,
Compatibility re-export of wrap_err for interop with anyhow
sourcepub fn chain(&self) -> Chain<'_>
pub fn chain(&self) -> Chain<'_>
An iterator of the chain of source errors contained by this Report.
This iterator will visit every error in the cause chain of this error object, beginning with the error that this error object was created from.
Example
use miette::Report;
use std::io;
pub fn underlying_io_error_kind(error: &Report) -> Option<io::ErrorKind> {
for cause in error.chain() {
if let Some(io_error) = cause.downcast_ref::<io::Error>() {
return Some(io_error.kind());
}
}
None
}
sourcepub fn root_cause(&self) -> &(dyn StdError + 'static)
pub fn root_cause(&self) -> &(dyn StdError + 'static)
The lowest level cause of this error — this error’s cause’s cause’s cause etc.
The root cause is the last error in the iterator produced by
chain()
.
sourcepub fn is<E>(&self) -> boolwhere
E: Display + Debug + Send + Sync + 'static,
pub fn is<E>(&self) -> boolwhere
E: Display + Debug + Send + Sync + 'static,
Returns true if E
is the type held by this error object.
For errors constructed from messages, this method returns true if E
matches the type of the message D
or the type of the error on
which the message has been attached. For details about the
interaction between message and downcasting, see here.
sourcepub fn downcast<E>(self) -> Result<E, Self>where
E: Display + Debug + Send + Sync + 'static,
pub fn downcast<E>(self) -> Result<E, Self>where
E: Display + Debug + Send + Sync + 'static,
Attempt to downcast the error object to a concrete type.
sourcepub fn downcast_ref<E>(&self) -> Option<&E>where
E: Display + Debug + Send + Sync + 'static,
pub fn downcast_ref<E>(&self) -> Option<&E>where
E: Display + Debug + Send + Sync + 'static,
Downcast this error object by reference.
Example
// If the error was caused by redaction, then return a tombstone instead
// of the content.
match root_cause.downcast_ref::<DataStoreError>() {
Some(DataStoreError::Censored(_)) => Ok(Poll::Ready(REDACTED_CONTENT)),
None => Err(error),
}
sourcepub fn downcast_mut<E>(&mut self) -> Option<&mut E>where
E: Display + Debug + Send + Sync + 'static,
pub fn downcast_mut<E>(&mut self) -> Option<&mut E>where
E: Display + Debug + Send + Sync + 'static,
Downcast this error object by mutable reference.
sourcepub fn handler(&self) -> &dyn ReportHandler
pub fn handler(&self) -> &dyn ReportHandler
Get a reference to the Handler for this Report.
sourcepub fn handler_mut(&mut self) -> &mut dyn ReportHandler
pub fn handler_mut(&mut self) -> &mut dyn ReportHandler
Get a mutable reference to the Handler for this Report.
sourcepub fn with_source_code(
self,
source_code: impl SourceCode + Send + Sync + 'static
) -> Report
pub fn with_source_code(
self,
source_code: impl SourceCode + Send + Sync + 'static
) -> Report
Provide source code for this error
Trait Implementations
sourceimpl AsRef<dyn Diagnostic + 'static> for Report
impl AsRef<dyn Diagnostic + 'static> for Report
sourcefn as_ref(&self) -> &(dyn Diagnostic + 'static)
fn as_ref(&self) -> &(dyn Diagnostic + 'static)
sourceimpl AsRef<dyn Diagnostic + Send + Sync + 'static> for Report
impl AsRef<dyn Diagnostic + Send + Sync + 'static> for Report
sourcefn as_ref(&self) -> &(dyn Diagnostic + Send + Sync + 'static)
fn as_ref(&self) -> &(dyn Diagnostic + Send + Sync + 'static)
sourceimpl Borrow<dyn Diagnostic + 'static> for Report
impl Borrow<dyn Diagnostic + 'static> for Report
sourcefn borrow(&self) -> &(dyn Diagnostic + 'static)
fn borrow(&self) -> &(dyn Diagnostic + 'static)
sourceimpl From<Report> for Box<dyn Diagnostic + 'static>
impl From<Report> for Box<dyn Diagnostic + 'static>
Auto Trait Implementations
impl !RefUnwindSafe for Report
impl Send for Report
impl Sync for Report
impl Unpin for Report
impl !UnwindSafe for Report
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
sourceimpl<D> OwoColorize for D
impl<D> OwoColorize for D
sourcefn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
sourcefn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
sourcefn black(&'a self) -> FgColorDisplay<'a, Black, Self>
fn black(&'a self) -> FgColorDisplay<'a, Black, Self>
sourcefn on_black(&'a self) -> BgColorDisplay<'a, Black, Self>
fn on_black(&'a self) -> BgColorDisplay<'a, Black, Self>
sourcefn red(&'a self) -> FgColorDisplay<'a, Red, Self>
fn red(&'a self) -> FgColorDisplay<'a, Red, Self>
sourcefn on_red(&'a self) -> BgColorDisplay<'a, Red, Self>
fn on_red(&'a self) -> BgColorDisplay<'a, Red, Self>
sourcefn green(&'a self) -> FgColorDisplay<'a, Green, Self>
fn green(&'a self) -> FgColorDisplay<'a, Green, Self>
sourcefn on_green(&'a self) -> BgColorDisplay<'a, Green, Self>
fn on_green(&'a self) -> BgColorDisplay<'a, Green, Self>
sourcefn yellow(&'a self) -> FgColorDisplay<'a, Yellow, Self>
fn yellow(&'a self) -> FgColorDisplay<'a, Yellow, Self>
sourcefn on_yellow(&'a self) -> BgColorDisplay<'a, Yellow, Self>
fn on_yellow(&'a self) -> BgColorDisplay<'a, Yellow, Self>
sourcefn blue(&'a self) -> FgColorDisplay<'a, Blue, Self>
fn blue(&'a self) -> FgColorDisplay<'a, Blue, Self>
sourcefn on_blue(&'a self) -> BgColorDisplay<'a, Blue, Self>
fn on_blue(&'a self) -> BgColorDisplay<'a, Blue, Self>
sourcefn magenta(&'a self) -> FgColorDisplay<'a, Magenta, Self>
fn magenta(&'a self) -> FgColorDisplay<'a, Magenta, Self>
sourcefn on_magenta(&'a self) -> BgColorDisplay<'a, Magenta, Self>
fn on_magenta(&'a self) -> BgColorDisplay<'a, Magenta, Self>
sourcefn purple(&'a self) -> FgColorDisplay<'a, Magenta, Self>
fn purple(&'a self) -> FgColorDisplay<'a, Magenta, Self>
sourcefn on_purple(&'a self) -> BgColorDisplay<'a, Magenta, Self>
fn on_purple(&'a self) -> BgColorDisplay<'a, Magenta, Self>
sourcefn cyan(&'a self) -> FgColorDisplay<'a, Cyan, Self>
fn cyan(&'a self) -> FgColorDisplay<'a, Cyan, Self>
sourcefn on_cyan(&'a self) -> BgColorDisplay<'a, Cyan, Self>
fn on_cyan(&'a self) -> BgColorDisplay<'a, Cyan, Self>
sourcefn white(&'a self) -> FgColorDisplay<'a, White, Self>
fn white(&'a self) -> FgColorDisplay<'a, White, Self>
sourcefn on_white(&'a self) -> BgColorDisplay<'a, White, Self>
fn on_white(&'a self) -> BgColorDisplay<'a, White, Self>
sourcefn default_color(&'a self) -> FgColorDisplay<'a, Default, Self>
fn default_color(&'a self) -> FgColorDisplay<'a, Default, Self>
sourcefn on_default_color(&'a self) -> BgColorDisplay<'a, Default, Self>
fn on_default_color(&'a self) -> BgColorDisplay<'a, Default, Self>
sourcefn bright_black(&'a self) -> FgColorDisplay<'a, BrightBlack, Self>
fn bright_black(&'a self) -> FgColorDisplay<'a, BrightBlack, Self>
sourcefn on_bright_black(&'a self) -> BgColorDisplay<'a, BrightBlack, Self>
fn on_bright_black(&'a self) -> BgColorDisplay<'a, BrightBlack, Self>
sourcefn bright_red(&'a self) -> FgColorDisplay<'a, BrightRed, Self>
fn bright_red(&'a self) -> FgColorDisplay<'a, BrightRed, Self>
sourcefn on_bright_red(&'a self) -> BgColorDisplay<'a, BrightRed, Self>
fn on_bright_red(&'a self) -> BgColorDisplay<'a, BrightRed, Self>
sourcefn bright_green(&'a self) -> FgColorDisplay<'a, BrightGreen, Self>
fn bright_green(&'a self) -> FgColorDisplay<'a, BrightGreen, Self>
sourcefn on_bright_green(&'a self) -> BgColorDisplay<'a, BrightGreen, Self>
fn on_bright_green(&'a self) -> BgColorDisplay<'a, BrightGreen, Self>
sourcefn bright_yellow(&'a self) -> FgColorDisplay<'a, BrightYellow, Self>
fn bright_yellow(&'a self) -> FgColorDisplay<'a, BrightYellow, Self>
sourcefn on_bright_yellow(&'a self) -> BgColorDisplay<'a, BrightYellow, Self>
fn on_bright_yellow(&'a self) -> BgColorDisplay<'a, BrightYellow, Self>
sourcefn bright_blue(&'a self) -> FgColorDisplay<'a, BrightBlue, Self>
fn bright_blue(&'a self) -> FgColorDisplay<'a, BrightBlue, Self>
sourcefn on_bright_blue(&'a self) -> BgColorDisplay<'a, BrightBlue, Self>
fn on_bright_blue(&'a self) -> BgColorDisplay<'a, BrightBlue, Self>
sourcefn bright_magenta(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
fn bright_magenta(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
sourcefn on_bright_magenta(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
fn on_bright_magenta(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
sourcefn bright_purple(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
fn bright_purple(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
sourcefn on_bright_purple(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
fn on_bright_purple(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
sourcefn bright_cyan(&'a self) -> FgColorDisplay<'a, BrightCyan, Self>
fn bright_cyan(&'a self) -> FgColorDisplay<'a, BrightCyan, Self>
sourcefn on_bright_cyan(&'a self) -> BgColorDisplay<'a, BrightCyan, Self>
fn on_bright_cyan(&'a self) -> BgColorDisplay<'a, BrightCyan, Self>
sourcefn bright_white(&'a self) -> FgColorDisplay<'a, BrightWhite, Self>
fn bright_white(&'a self) -> FgColorDisplay<'a, BrightWhite, Self>
sourcefn on_bright_white(&'a self) -> BgColorDisplay<'a, BrightWhite, Self>
fn on_bright_white(&'a self) -> BgColorDisplay<'a, BrightWhite, Self>
sourcefn bold(&'a self) -> BoldDisplay<'a, Self>
fn bold(&'a self) -> BoldDisplay<'a, Self>
sourcefn dimmed(&'a self) -> DimDisplay<'a, Self>
fn dimmed(&'a self) -> DimDisplay<'a, Self>
sourcefn italic(&'a self) -> ItalicDisplay<'a, Self>
fn italic(&'a self) -> ItalicDisplay<'a, Self>
sourcefn underline(&'a self) -> UnderlineDisplay<'a, Self>
fn underline(&'a self) -> UnderlineDisplay<'a, Self>
sourcefn blink(&'a self) -> BlinkDisplay<'a, Self>
fn blink(&'a self) -> BlinkDisplay<'a, Self>
sourcefn blink_fast(&'a self) -> BlinkFastDisplay<'a, Self>
fn blink_fast(&'a self) -> BlinkFastDisplay<'a, Self>
sourcefn reversed(&'a self) -> ReversedDisplay<'a, Self>
fn reversed(&'a self) -> ReversedDisplay<'a, Self>
sourcefn strikethrough(&'a self) -> StrikeThroughDisplay<'a, Self>
fn strikethrough(&'a self) -> StrikeThroughDisplay<'a, Self>
sourcefn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg
or
a color-specific method, such as OwoColorize::green
, Read moresourcefn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg
or
a color-specific method, such as OwoColorize::on_yellow
, Read more