//! Error handling for Bevy systems, commands, and observers.1//!2//! When a system is added to a [`Schedule`], and its return type is that of [`Result`], then Bevy3//! considers those systems to be "fallible", and the ECS scheduler will special-case the [`Err`]4//! variant of the returned `Result`.5//!6//! All [`BevyError`]s returned by a system, observer or command are handled by an "error handler". By default, the7//! [`panic`] error handler function is used, resulting in a panic with the error message attached.8//!9//! You can change the default behavior by registering a custom error handler:10//! Use [`DefaultErrorHandler`] to set a custom error handler function for a world,11//! or `App::set_error_handler` for a whole app.12//! In practice, this is generally feature-flagged: panicking or loudly logging errors in development,13//! and quietly logging or ignoring them in production to avoid crashing the app.14//!15//! Bevy provides a number of pre-built error-handlers for you to use:16//!17//! - [`panic`] – panics with the system error18//! - [`error`] – logs the system error at the `error` level19//! - [`warn`] – logs the system error at the `warn` level20//! - [`info`] – logs the system error at the `info` level21//! - [`debug`] – logs the system error at the `debug` level22//! - [`trace`] – logs the system error at the `trace` level23//! - [`ignore`] – ignores the system error24//!25//! However, you can use any custom error handler logic by providing your own function (or26//! non-capturing closure that coerces to the function signature) as long as it matches the27//! signature:28//!29//! ```rust,ignore30//! fn(BevyError, ErrorContext)31//! ```32//!33//! The [`ErrorContext`] allows you to access additional details relevant to providing34//! context surrounding the error – such as the system's [`name`] – in your error messages.35//!36//! ```rust, ignore37//! use bevy_ecs::error::{BevyError, ErrorContext, DefaultErrorHandler};38//! use log::trace;39//!40//! fn my_error_handler(error: BevyError, ctx: ErrorContext) {41//! if ctx.name().ends_with("plz_ignore") {42//! trace!("Nothing to see here, move along.");43//! return;44//! }45//! bevy_ecs::error::error(error, ctx);46//! }47//!48//! fn main() {49//! let mut world = World::new();50//! world.insert_resource(DefaultErrorHandler(my_error_handler));51//! // Use your world here52//! }53//! ```54//!55//! If you need special handling of individual fallible systems, you can use Bevy's [`system piping56//! feature`] to capture the [`Result`] output of the system and handle it accordingly.57//!58//! When working with commands, you can handle the result of each command separately using the [`HandleError::handle_error_with`] method.59//!60//! [`Schedule`]: crate::schedule::Schedule61//! [`panic`]: panic()62//! [`World`]: crate::world::World63//! [`System`]: crate::system::System64//! [`name`]: crate::system::System::name65//! [`system piping feature`]: crate::system::In6667mod bevy_error;68mod command_handling;69mod handler;7071pub use bevy_error::*;72pub use command_handling::*;73pub use handler::*;7475/// A result type for use in fallible systems, commands and observers.76///77/// The [`BevyError`] type is a type-erased error type with optional Bevy-specific diagnostics.78pub type Result<T = (), E = BevyError> = core::result::Result<T, E>;798081