Error

Struct 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(kind: ErrorKind) -> Self

Create a new error

Source

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

Create a new error with a span

Source

pub fn new_other(e: impl Into<Error>) -> Self

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

Source

pub fn new_native(e: impl Into<Error>) -> Self

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

Source

pub fn new_value(e: impl Into<Error>) -> Self

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

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 call_stack(&self) -> &CallStack

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

Source

pub fn into_internal_error(self) -> Error

Change error kind to internal error.

Trait Implementations§

Source§

impl Debug for Error

Source§

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

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

impl Display for Error

Source§

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

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

impl From<Error> for Error

Source§

fn from(e: Error) -> Self

Converts to this type from the input type.
Source§

impl From<LexemeError> for Error

Source§

fn from(e: LexemeError) -> Self

Converts to this type from the input type.
Source§

impl From<TypeExprUnpackError> for Error

Source§

fn from(e: TypeExprUnpackError) -> Self

Converts to this type from the input type.
Source§

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

Source§

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

Converts to this type from the input type.

Auto Trait Implementations§

§

impl Freeze for Error

§

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§

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>,

Source§

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>,

Source§

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.