Struct starlark::errors::Diagnostic
source · pub struct Diagnostic {
pub message: Error,
pub span: Option<FileSpan>,
pub call_stack: CallStack,
}
Expand description
An error plus its origination location and call stack.
The underlying message
is an anyhow::Error
.
The Diagnostic
structure itself usually stored within an anyhow::Error
.
Fields§
§message: Error
Underlying error for the Diagnostic
.
Should never be of type Diagnostic
itself.
span: Option<FileSpan>
Location where the error originated.
call_stack: CallStack
Call stack where the error originated.
Implementations§
source§impl Diagnostic
impl Diagnostic
sourcepub fn modify(err: Error, f: impl FnOnce(&mut Diagnostic)) -> Error
pub fn modify(err: Error, f: impl FnOnce(&mut Diagnostic)) -> Error
Modify an error by attaching diagnostic information to it - e.g. span
/call_stack
.
If given an anyhow::Error
which is a Diagnostic
, it will add the information to the
existing Diagnostic
. If not, it will wrap the error in Diagnostic
.
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 Diagnostic::call_stack
field, unless it’s already been set.
sourcepub fn eprint(err: &Error)
pub fn eprint(err: &Error)
Print an error to the stderr stream. If the error is a Diagnostic
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).