pub struct RichError {
pub code: ErrorCode,
pub message: String,
pub broad_span: Span,
pub label: Option<Label>,
pub notes: Vec<Note>,
}Expand description
A highly detailed error type designed for:
- Compilers (or anything similar)
- Tracebacks
- Any situation where a source file would provide valuable context for the user
This serves as a sort of wrapper around ariadne, although it is missing much of
ariadne’s functionality. The point is to have a simple interface for constructing error
reports that works well enough for sufficiently simple applications.
As a word of caution, this higher level of detail comes at the cost of higher memory usage. The
struct alone is around 7 times larger than a String, and some features may incur extra
heap allocations as well. Thus, it is not advisable to use rich errors unless an ordinary error
is truly insufficient.
Fields§
§code: ErrorCodeThe error code.
message: StringThe error message.
This is meant to be a description of the general error specified by code rather than a
verbose description of precisely what failed. More details should be sent through label
and/or notes.
broad_span: SpanThe broad area in the source file that caused the error.
The exact location of the error can be specified via label.
label: Option<Label>An additional error message associated with a specific area of the source code.
notes: Vec<Note>An arbitrary number of notes that provide additional context and/or assistance to the user.
Implementations§
Source§impl RichError
impl RichError
Sourcepub fn new<E>(err: E, broad_span: Span) -> Selfwhere
E: ToErrorCode + ToString,
pub fn new<E>(err: E, broad_span: Span) -> Selfwhere
E: ToErrorCode + ToString,
Constructs a new rich error.
To add additional metadata to this message, use the relevant builder methods.
Sourcepub fn with_note<S>(self, message: S) -> Selfwhere
S: ToString,
pub fn with_note<S>(self, message: S) -> Selfwhere
S: ToString,
Adds an ordinary note to this error.
Sourcepub fn with_help<S>(self, message: S) -> Selfwhere
S: ToString,
pub fn with_help<S>(self, message: S) -> Selfwhere
S: ToString,
Adds a note with a help message to this error.
Sourcepub fn with_label(self, label: Label) -> Self
pub fn with_label(self, label: Label) -> Self
Adds a label to this error.
If a label was already present, this overwrites it.
Sourcepub fn with_narrow_span(self, span: Span) -> Self
pub fn with_narrow_span(self, span: Span) -> Self
Specifies the exact location of the error within the broader span.
This is similar to creating a blank label with the provided span, but it also
handles the case where label was already set. In that case, label’s message will be
preserved while its span is overwritten.
Trait Implementations§
impl Eq for RichError
impl StructuralPartialEq for RichError
Auto Trait Implementations§
impl Freeze for RichError
impl RefUnwindSafe for RichError
impl Send for RichError
impl Sync for RichError
impl Unpin for RichError
impl UnwindSafe for RichError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);