Skip to main content

BevyError

Struct BevyError 

Source
pub struct BevyError { /* private fields */ }
Expand description

The built in “universal” Bevy error type. This has a blanket From impl for any type that implements Rust’s Error, meaning it can be used as a “catch all” error.

§Severity

Each BevyError carries a Severity value that indicates how serious the error is. While the levels within Severity correspond to traditional logging levels, these levels are fundamentally advisory metadata. The fallback error handler ultimately has discretion to respond to each of these errors according to its configuration. The error handler ultimately has discretion to respond to each of these errors according to its configuration. You can change the behavior of the fallback handler by modifying the FallbackErrorHandler resource.

By default, errors without an assigned severity use Severity::Panic, and will cause your application to panic. You can change the severity of an error by using with_severity, or map_severity on any Result type.

§Backtraces

When used with the backtrace Cargo feature, it can capture a backtrace when the error is constructed (generally in the From impl).

To enable backtrace capture on supported platforms, set the RUST_BACKTRACE environment variable. See Backtrace::capture for details.

When the error is printed, the backtrace will be displayed. By default, the backtrace will be trimmed down to filter out noise. To see the full backtrace, set the BEVY_BACKTRACE=full environment variable.

§Usage


fn fallible_system() -> Result<(), BevyError> {
    // This will result in Rust's built-in ParseIntError, which will automatically
    // be converted into a BevyError.
    let parsed: usize = "I am not a number".parse()?;
    Ok(())
}

Implementations§

Source§

impl BevyError

Source

pub fn new<E>(severity: Severity, error: E) -> Self
where Box<dyn Error + Sync + Send>: From<E>,

Constructs a new BevyError with the given Severity.

The error will be stored as a Box<dyn Error + Send + Sync>.

The easiest way to use this is to pass in a string. This works because any type that can be converted into a Box<dyn Error + Send + Sync> can be used, and str is one such type.

§Examples

fn some_function(val: i64) -> Result<(), BevyError> {
    if val < 0 {
        let error =
            BevyError::new(Severity::Panic, format!("Value can't be negative {val}"));
        return Err(error);
    }

    // ...
    Ok(())
}
Source

pub fn ignore<E>(error: E) -> Self
where Box<dyn Error + Send + Sync>: From<E>,

Creates a new BevyError with the Severity::Ignore severity.

This is a shorthand for BevyError::new(Severity::Ignore, error).

Source

pub fn trace<E>(error: E) -> Self
where Box<dyn Error + Send + Sync>: From<E>,

Creates a new BevyError with the Severity::Trace severity.

This is a shorthand for BevyError::new(Severity::Trace, error).

Source

pub fn debug<E>(error: E) -> Self
where Box<dyn Error + Send + Sync>: From<E>,

Creates a new BevyError with the Severity::Debug severity.

This is a shorthand for BevyError::new(Severity::Debug, error).

Source

pub fn info<E>(error: E) -> Self
where Box<dyn Error + Send + Sync>: From<E>,

Creates a new BevyError with the Severity::Info severity.

This is a shorthand for BevyError::new(Severity::Info, error).

Source

pub fn warning<E>(error: E) -> Self
where Box<dyn Error + Send + Sync>: From<E>,

Creates a new BevyError with the Severity::Warning severity.

This is a shorthand for BevyError::new(Severity::Warning, error).

Source

pub fn error<E>(error: E) -> Self
where Box<dyn Error + Send + Sync>: From<E>,

Creates a new BevyError with the Severity::Error severity.

This is a shorthand for BevyError::new(Severity::Error, error).

Source

pub fn panic<E>(error: E) -> Self
where Box<dyn Error + Send + Sync>: From<E>,

Creates a new BevyError with the Severity::Panic severity.

This is a shorthand for BevyError::new(Severity::Panic, error).

Source

pub fn is<E: Error + 'static>(&self) -> bool

Checks if the internal error is of the given type.

Source

pub fn downcast_ref<E: Error + 'static>(&self) -> Option<&E>

Attempts to downcast the internal error to the given type.

Source§

impl BevyError

Source

pub fn severity(&self) -> Severity

Returns the severity of this error.

Source

pub fn with_severity(self, severity: Severity) -> Self

Returns this error with its severity overridden.

Note that this doesn’t change the underlying error value; only the Severity metadata used by the error handler.

Trait Implementations§

Source§

impl Debug for BevyError

Source§

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

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

impl Display for BevyError

Source§

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

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

impl<E> From<E> for BevyError
where Box<dyn Error + Send + Sync + 'static>: From<E>,

Source§

fn from(error: E) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSend for T
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Send + Sync>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<!> for T

Source§

fn from(t: !) -> T

Converts to this type from the input type.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

Source§

const WITNESS: W = W::MAKE

A constant of the type witness
Source§

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

Source§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
Source§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
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> IntoResult<T> for T

Source§

fn into_result(self) -> Result<T, RunSystemError>

Converts this type into the system output type.
Source§

impl<A> Is for A
where A: Any,

Source§

fn is<T>() -> bool
where T: Any,

Checks if the current type “is” another type, using a TypeId equality comparison. This is most useful in the context of generic logic. Read more
Source§

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

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.
Source§

impl<T> ConditionalSend for T
where T: Send,

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,