Struct color_eyre::config::HookBuilder [−][src]
Builder for customizing the behavior of the global panic and error report hooks
Implementations
impl HookBuilder
[src]
pub fn new() -> Self
[src]
Construct a HookBuilder
Details
By default this function calls add_default_filters()
and
capture_span_trace_by_default(true)
. To get a HookBuilder
with all
features disabled by default call HookBuilder::blank()
.
Example
use color_eyre::config::HookBuilder; HookBuilder::new() .install() .unwrap();
pub fn blank() -> Self
[src]
Construct a HookBuilder with minimal features enabled
pub fn theme(self, theme: Theme) -> Self
[src]
Set the global styles that color_eyre
should use.
Tip: You can test new styles by editing examples/theme.rs
in the color-eyre
repository.
pub fn panic_section<S: Display + Send + Sync + 'static>(
self,
section: S
) -> Self
[src]
self,
section: S
) -> Self
Add a custom section to the panic hook that will be printed in the panic message.
Examples
color_eyre::config::HookBuilder::default() .panic_section("consider reporting the bug at https://github.com/yaahc/color-eyre") .install() .unwrap()
pub fn panic_message<S: PanicMessage>(self, section: S) -> Self
[src]
Overrides the main error message printing section at the start of panic reports
Examples
use std::{panic::Location, fmt}; use color_eyre::section::PanicMessage; use owo_colors::OwoColorize; struct MyPanicMessage; color_eyre::config::HookBuilder::default() .panic_message(MyPanicMessage) .install() .unwrap(); impl PanicMessage for MyPanicMessage { fn display(&self, pi: &std::panic::PanicInfo<'_>, f: &mut fmt::Formatter<'_>) -> fmt::Result { writeln!(f, "{}", "The application panicked (crashed).".red())?; // Print panic message. let payload = pi .payload() .downcast_ref::<String>() .map(String::as_str) .or_else(|| pi.payload().downcast_ref::<&str>().cloned()) .unwrap_or("<non string panic payload>"); write!(f, "Message: ")?; writeln!(f, "{}", payload.cyan())?; // If known, print panic location. write!(f, "Location: ")?; if let Some(loc) = pi.location() { write!(f, "{}", loc.file().purple())?; write!(f, ":")?; write!(f, "{}", loc.line().purple())?; write!(f, "\n\nConsider reporting the bug at {}", custom_url(loc, payload))?; } else { write!(f, "<unknown>")?; } Ok(()) } } fn custom_url(location: &Location<'_>, message: &str) -> impl fmt::Display { "todo" }
pub fn issue_url<S: ToString>(self, url: S) -> Self
[src]
issue-url
only.Set an upstream github repo and enable issue reporting url generation
Details
Once enabled, color-eyre will generate urls that will create customized issues pre-populated with information about the associated error report.
Additional information can be added to the metadata table in the
generated urls by calling add_issue_metadata
when configuring the
HookBuilder.
Examples
color_eyre::config::HookBuilder::default() .issue_url(concat!(env!("CARGO_PKG_REPOSITORY"), "/issues/new")) .install() .unwrap();
pub fn add_issue_metadata<K, V>(self, key: K, value: V) -> Self where
K: Display,
V: Display + Send + Sync + 'static,
[src]
K: Display,
V: Display + Send + Sync + 'static,
issue-url
only.Add a new entry to the metadata table in generated github issue urls
Note: this metadata will be ignored if no issue_url
is set.
Examples
color_eyre::config::HookBuilder::default() .issue_url(concat!(env!("CARGO_PKG_REPOSITORY"), "/issues/new")) .add_issue_metadata("version", env!("CARGO_PKG_VERSION")) .install() .unwrap();
pub fn issue_filter<F>(self, predicate: F) -> Self where
F: Fn(ErrorKind<'_>) -> bool + Send + Sync + 'static,
[src]
F: Fn(ErrorKind<'_>) -> bool + Send + Sync + 'static,
issue-url
only.Configures a filter for disabling issue url generation for certain kinds of errors
If the closure returns true
, then the issue url will be generated.
Examples
color_eyre::config::HookBuilder::default() .issue_url(concat!(env!("CARGO_PKG_REPOSITORY"), "/issues/new")) .issue_filter(|kind| match kind { color_eyre::ErrorKind::NonRecoverable(payload) => { let payload = payload .downcast_ref::<String>() .map(String::as_str) .or_else(|| payload.downcast_ref::<&str>().cloned()) .unwrap_or("<non string panic payload>"); !payload.contains("my irrelevant error message") }, color_eyre::ErrorKind::Recoverable(error) => !error.is::<std::fmt::Error>(), }) .install() .unwrap();
pub fn capture_span_trace_by_default(self, cond: bool) -> Self
[src]
Configures the default capture mode for SpanTraces
in error reports and panics
pub fn display_env_section(self, cond: bool) -> Self
[src]
Configures the enviroment varible info section and whether or not it is displayed
pub fn add_frame_filter(self, filter: Box<FilterCallback>) -> Self
[src]
Add a custom filter to the set of frame filters
Examples
color_eyre::config::HookBuilder::default() .add_frame_filter(Box::new(|frames| { let filters = &[ "uninteresting_function", ]; frames.retain(|frame| { !filters.iter().any(|f| { let name = if let Some(name) = frame.name.as_ref() { name.as_str() } else { return true; }; name.starts_with(f) }) }); })) .install() .unwrap();
pub fn install(self) -> Result<(), Report>
[src]
Install the given Hook as the global error report hook
pub fn add_default_filters(self) -> Self
[src]
Add the default set of filters to this HookBuilder
’s configuration
pub fn into_hooks(self) -> (PanicHook, EyreHook)
[src]
Create a PanicHook
and EyreHook
from this HookBuilder
.
This can be used if you want to combine these handlers with other handlers.
Trait Implementations
impl Default for HookBuilder
[src]
Auto Trait Implementations
impl !RefUnwindSafe for HookBuilder
impl Send for HookBuilder
impl Sync for HookBuilder
impl Unpin for HookBuilder
impl !UnwindSafe for HookBuilder
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<D> OwoColorize for D
[src]
pub fn fg<C>(&'a self) -> FgColorDisplay<'a, C, Self> where
C: Color,
[src]
C: Color,
pub fn bg<C>(&'a self) -> BgColorDisplay<'a, C, Self> where
C: Color,
[src]
C: Color,
pub fn black(&'a self) -> FgColorDisplay<'a, Black, Self>
[src]
pub fn on_black(&'a self) -> BgColorDisplay<'a, Black, Self>
[src]
pub fn red(&'a self) -> FgColorDisplay<'a, Red, Self>
[src]
pub fn on_red(&'a self) -> BgColorDisplay<'a, Red, Self>
[src]
pub fn green(&'a self) -> FgColorDisplay<'a, Green, Self>
[src]
pub fn on_green(&'a self) -> BgColorDisplay<'a, Green, Self>
[src]
pub fn yellow(&'a self) -> FgColorDisplay<'a, Yellow, Self>
[src]
pub fn on_yellow(&'a self) -> BgColorDisplay<'a, Yellow, Self>
[src]
pub fn blue(&'a self) -> FgColorDisplay<'a, Blue, Self>
[src]
pub fn on_blue(&'a self) -> BgColorDisplay<'a, Blue, Self>
[src]
pub fn magenta(&'a self) -> FgColorDisplay<'a, Magenta, Self>
[src]
pub fn on_magenta(&'a self) -> BgColorDisplay<'a, Magenta, Self>
[src]
pub fn purple(&'a self) -> FgColorDisplay<'a, Magenta, Self>
[src]
pub fn on_purple(&'a self) -> BgColorDisplay<'a, Magenta, Self>
[src]
pub fn cyan(&'a self) -> FgColorDisplay<'a, Cyan, Self>
[src]
pub fn on_cyan(&'a self) -> BgColorDisplay<'a, Cyan, Self>
[src]
pub fn white(&'a self) -> FgColorDisplay<'a, White, Self>
[src]
pub fn on_white(&'a self) -> BgColorDisplay<'a, White, Self>
[src]
pub fn bright_black(&'a self) -> FgColorDisplay<'a, BrightBlack, Self>
[src]
pub fn on_bright_black(&'a self) -> BgColorDisplay<'a, BrightBlack, Self>
[src]
pub fn bright_red(&'a self) -> FgColorDisplay<'a, BrightRed, Self>
[src]
pub fn on_bright_red(&'a self) -> BgColorDisplay<'a, BrightRed, Self>
[src]
pub fn bright_green(&'a self) -> FgColorDisplay<'a, BrightGreen, Self>
[src]
pub fn on_bright_green(&'a self) -> BgColorDisplay<'a, BrightGreen, Self>
[src]
pub fn bright_yellow(&'a self) -> FgColorDisplay<'a, BrightYellow, Self>
[src]
pub fn on_bright_yellow(&'a self) -> BgColorDisplay<'a, BrightYellow, Self>
[src]
pub fn bright_blue(&'a self) -> FgColorDisplay<'a, BrightBlue, Self>
[src]
pub fn on_bright_blue(&'a self) -> BgColorDisplay<'a, BrightBlue, Self>
[src]
pub fn bright_magenta(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
[src]
pub fn on_bright_magenta(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
[src]
pub fn bright_purple(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
[src]
pub fn on_bright_purple(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
[src]
pub fn bright_cyan(&'a self) -> FgColorDisplay<'a, BrightCyan, Self>
[src]
pub fn on_bright_cyan(&'a self) -> BgColorDisplay<'a, BrightCyan, Self>
[src]
pub fn bright_white(&'a self) -> FgColorDisplay<'a, BrightWhite, Self>
[src]
pub fn on_bright_white(&'a self) -> BgColorDisplay<'a, BrightWhite, Self>
[src]
pub fn bold(&'a self) -> BoldDisplay<'a, Self>
[src]
pub fn dimmed(&'a self) -> DimDisplay<'a, Self>
[src]
pub fn italic(&'a self) -> ItalicDisplay<'a, Self>
[src]
pub fn underline(&'a self) -> UnderlineDisplay<'a, Self>
[src]
pub fn blink(&'a self) -> BlinkDisplay<'a, Self>
[src]
pub fn blink_fast(&'a self) -> BlinkFastDisplay<'a, Self>
[src]
pub fn reversed(&'a self) -> ReversedDisplay<'a, Self>
[src]
pub fn hidden(&'a self) -> HiddenDisplay<'a, Self>
[src]
pub fn strikethrough(&'a self) -> StrikeThroughDisplay<'a, Self>
[src]
pub fn color<Color>(
&'a self,
color: Color
) -> FgDynColorDisplay<'a, Color, Self> where
Color: DynColor,
[src]
&'a self,
color: Color
) -> FgDynColorDisplay<'a, Color, Self> where
Color: DynColor,
pub fn on_color<Color>(
&'a self,
color: Color
) -> BgDynColorDisplay<'a, Color, Self> where
Color: DynColor,
[src]
&'a self,
color: Color
) -> BgDynColorDisplay<'a, Color, Self> where
Color: DynColor,
pub fn truecolor(
&'a self,
r: u8,
g: u8,
b: u8
) -> FgDynColorDisplay<'a, Rgb, Self>
[src]
&'a self,
r: u8,
g: u8,
b: u8
) -> FgDynColorDisplay<'a, Rgb, Self>
pub fn on_truecolor(
&'a self,
r: u8,
g: u8,
b: u8
) -> BgDynColorDisplay<'a, Rgb, Self>
[src]
&'a self,
r: u8,
g: u8,
b: u8
) -> BgDynColorDisplay<'a, Rgb, Self>
pub fn style(&self, style: Style) -> Styled<&Self>
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,