#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum SoushiError {
#[error("script error: {0}")]
ScriptError(String),
#[error("compile error: {0}")]
CompileError(String),
#[error("io: {0}")]
IoError(#[from] std::io::Error),
#[error("no such script: {0}")]
NoSuchScript(String),
#[error("script file not found: {0}")]
ScriptFileNotFound(std::path::PathBuf),
#[error("script dir not found: {0}")]
ScriptDirNotFound(std::path::PathBuf),
}
impl SoushiError {
#[must_use]
pub fn is_script_error(&self) -> bool {
matches!(self, Self::ScriptError(_))
}
#[must_use]
pub fn is_compile_error(&self) -> bool {
matches!(self, Self::CompileError(_))
}
#[must_use]
pub fn is_io_error(&self) -> bool {
matches!(self, Self::IoError(_))
}
#[must_use]
pub fn is_not_found(&self) -> bool {
matches!(
self,
Self::NoSuchScript(_) | Self::ScriptFileNotFound(_) | Self::ScriptDirNotFound(_)
)
}
}
impl From<Box<rhai::EvalAltResult>> for SoushiError {
fn from(err: Box<rhai::EvalAltResult>) -> Self {
Self::ScriptError(err.to_string())
}
}
impl From<rhai::ParseError> for SoushiError {
fn from(err: rhai::ParseError) -> Self {
Self::CompileError(err.to_string())
}
}