use bevy::prelude::*;
use thiserror::Error;
#[derive(Error, Debug)]
pub enum Error {
#[error("saving error: {0}")]
Saving(Box<dyn std::error::Error + Send + Sync>),
#[error("loading error: {0}")]
Loading(Box<dyn std::error::Error + Send + Sync>),
#[error("flow error: {0}")]
Flow(#[from] crate::flows::FlowError),
#[cfg(feature = "reflect")]
#[error("scene spawn error: {0}")]
SceneSpawnError(#[from] bevy::scene::SceneSpawnError),
#[error("io error: {0}")]
IO(#[from] std::io::Error),
#[error("other error: {0}")]
Other(Box<dyn std::error::Error + Send + Sync>),
#[error("custom error: {0}")]
Custom(String),
}
impl Error {
pub fn saving(err: impl std::error::Error + Send + Sync + 'static) -> Self {
Self::Saving(Box::new(err))
}
pub fn loading(err: impl std::error::Error + Send + Sync + 'static) -> Self {
Self::Loading(Box::new(err))
}
pub fn other(error: impl std::error::Error + Send + Sync + 'static) -> Self {
Self::Other(Box::new(error))
}
pub fn custom(error: impl std::fmt::Display) -> Self {
Self::Custom(format!("{error}"))
}
}