pub struct Error(/* private fields */);
Expand description
An error produced by starlark.
This error is composed of an error kind, together with some diagnostic information indicating where it occurred.
In order to prevent accidental conversions to anyhow::Error
, this type intentionally does not
implement std::error::Error
. That should probably change in the future.
Implementations§
source§impl Error
impl Error
sourcepub fn new_spanned(kind: ErrorKind, span: Span, codemap: &CodeMap) -> Error
pub fn new_spanned(kind: ErrorKind, span: Span, codemap: &CodeMap) -> Error
Create a new error with a span
sourcepub fn new_other(e: impl Error + Send + Sync + 'static) -> Error
pub fn new_other(e: impl Error + Send + Sync + 'static) -> Error
Create a new error with no diagnostic and of kind ErrorKind::Other
pub fn has_diagnostic(&self) -> bool
sourcepub fn into_anyhow(self) -> Error
pub fn into_anyhow(self) -> Error
Convert this error into an anyhow::Error
sourcepub fn without_diagnostic<'a>(&'a self) -> impl Debug + Display + 'a
pub fn without_diagnostic<'a>(&'a self) -> impl Debug + Display + 'a
Returns a value that can be used to format this error without including the diagnostic information
This is the same as kind
, just a bit more explicit.
pub fn span(&self) -> Option<&FileSpan>
sourcepub fn set_span(&mut self, span: Span, codemap: &CodeMap)
pub fn set_span(&mut self, span: Span, codemap: &CodeMap)
Set the span, unless it’s already been set.
sourcepub fn set_call_stack(&mut self, call_stack: impl FnOnce() -> CallStack)
pub fn set_call_stack(&mut self, call_stack: impl FnOnce() -> CallStack)
Set the call_stack
field, unless it’s already been set.
sourcepub fn eprint(&self)
pub fn eprint(&self)
Print an error to the stderr stream. If the error has diagnostic information it will use color-codes when printing.
Note that this function doesn’t print any context information if the error is a diagnostic,
so you might prefer to use eprintln!("{:#}"), err)
if you suspect there is useful context
(although you won’t get pretty colors).