Struct starlark::Error

source ·
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

source

pub fn new(kind: ErrorKind) -> Error

Create a new error

source

pub fn new_spanned(kind: ErrorKind, span: Span, codemap: &CodeMap) -> Error

Create a new error with a span

source

pub fn new_other(e: impl Error + Send + Sync + 'static) -> Error

Create a new error with no diagnostic and of kind ErrorKind::Other

source

pub fn kind(&self) -> &ErrorKind

The kind of this error

source

pub fn into_kind(self) -> ErrorKind

Convert the error into the underlying kind

source

pub fn has_diagnostic(&self) -> bool

source

pub fn into_anyhow(self) -> Error

Convert this error into an anyhow::Error

source

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.

source

pub fn span(&self) -> Option<&FileSpan>

source

pub fn set_span(&mut self, span: Span, codemap: &CodeMap)

Set the span, unless it’s already been set.

source

pub fn set_call_stack(&mut self, call_stack: impl FnOnce() -> CallStack)

Set the call_stack field, unless it’s already been set.

source

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).

Trait Implementations§

source§

impl Debug for Error

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl Display for Error

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl From<DefError> for Error

source§

fn from(e: DefError) -> Error

Converts to this type from the input type.
source§

impl From<Error> for Error

source§

fn from(e: Error) -> Error

Converts to this type from the input type.
source§

impl From<LexemeError> for Error

source§

fn from(e: LexemeError) -> Error

Converts to this type from the input type.
source§

impl From<TypeExprUnpackError> for Error

source§

fn from(e: TypeExprUnpackError) -> Error

Converts to this type from the input type.
source§

impl From<ValueError> for Error

source§

fn from(e: ValueError) -> Self

Converts to this type from the input type.
source§

impl<T> From<WithDiagnostic<T>> for Error
where T: Into<Error>,

source§

fn from(e: WithDiagnostic<T>) -> Error

Converts to this type from the input type.

Auto Trait Implementations§

§

impl RefUnwindSafe for Error

§

impl Send for Error

§

impl Sync for Error

§

impl Unpin for Error

§

impl UnwindSafe for Error

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToAst for T

source§

fn ast(self, begin: usize, end: usize) -> Spanned<Self>

source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.