pub struct Report { /* private fields */ }Expand description
One error, panic or message, on its way to Flare.
Implementations§
Source§impl Report
impl Report
Sourcepub fn new<C, M>(
exception_class: C,
message: M,
location: &Location<'_>,
) -> Self
pub fn new<C, M>( exception_class: C, message: M, location: &Location<'_>, ) -> Self
Creates a report with an exception class and a message.
location is the place where the report was made, like
std::panic::Location::caller(). Without a stack trace, this place is the
only frame of the report.
§Examples
Location::caller() returns the place that called the current function.
Mark a helper function that creates reports with #[track_caller]. Then
Location::caller() returns the place that called the helper, and not a
place inside the helper:
use std::panic::Location;
use flareapp_core::Report;
#[track_caller]
fn payment_failed() -> Report {
Report::new("my_app::PaymentFailed", "payment failed", Location::caller())
}
// The location of this report is this line, not the line in the helper.
let report = payment_failed();Sourcepub fn from_error<E: ReportableError + ?Sized>(
error: &E,
location: &Location<'_>,
) -> Self
pub fn from_error<E: ReportableError + ?Sized>( error: &E, location: &Location<'_>, ) -> Self
Creates a report for an error. The exception class is the Rust type of the
error, and the message is its Display output.
For a dyn Error, the exception class is the class that
erased_exception_class returns. When that function finds no class, the
class is Error.
Sourcepub fn from_erased_error(
error: &(dyn Error + 'static),
location: &Location<'_>,
) -> Self
pub fn from_erased_error( error: &(dyn Error + 'static), location: &Location<'_>, ) -> Self
Creates a report for an error whose type is hidden, like the error in a
Box<dyn Error>. The message is the Display output of the error.
The exception class is the class that erased_exception_class returns,
so a std::io::Error gets its real type name. When that function finds no
class, the class is Error.
Sourcepub fn from_message<M: Into<String>>(
message: M,
level: Level,
location: &Location<'_>,
) -> Self
pub fn from_message<M: Into<String>>( message: M, level: Level, location: &Location<'_>, ) -> Self
Creates a report for a message, like a log line that needs attention.
Sourcepub fn exception_class(&self) -> &str
pub fn exception_class(&self) -> &str
Returns the exception class, like std::io::error::Error.
Sourcepub fn set_exception_class<C: Into<String>>(&mut self, exception_class: C)
pub fn set_exception_class<C: Into<String>>(&mut self, exception_class: C)
Changes the exception class, which Flare groups errors by.
Sourcepub fn handled(&self) -> bool
pub fn handled(&self) -> bool
Returns true when your code handled the error, and false for a panic.
Sourcepub fn set_handled(&mut self, handled: bool)
pub fn set_handled(&mut self, handled: bool)
Marks the error as handled by your code (true, the default) or not.
Sourcepub fn set_context<K: Into<String>, V: Into<Value>>(&mut self, key: K, value: V)
pub fn set_context<K: Into<String>, V: Into<Value>>(&mut self, key: K, value: V)
Adds a piece of context to this report only.
Sourcepub fn set_attribute<K: Into<String>, V: Into<Value>>(
&mut self,
key: K,
value: V,
)
pub fn set_attribute<K: Into<String>, V: Into<Value>>( &mut self, key: K, value: V, )
Adds an attribute to this report only, like thread.name.
Sourcepub fn set_location(&mut self, location: Frame)
pub fn set_location(&mut self, location: Frame)
Sets the place where the report was made, when it differs from the
location given to Report::new. Without a stack trace, this place is
the only frame.
Sourcepub fn set_frames<R: ResolveFrames + 'static>(&mut self, frames: R)
pub fn set_frames<R: ResolveFrames + 'static>(&mut self, frames: R)
Sets the stack trace. The worker thread resolves it before sending.