use thiserror::Error;
#[derive(Debug, Error, Clone)]
#[allow(missing_docs)]
pub enum Error {
#[error("{0}")]
StringError(String),
#[error("missing os module in the prelude")]
MissingOsModule,
#[error("no exported function named '{0}' found")]
MissingFunction(String),
#[error("{error}")]
CompileError {
error: String,
is_indentation_error: bool,
},
#[cfg(feature = "serde")]
#[error(transparent)]
SerdeError(#[from] koto_serde::Error),
}
impl Error {
pub fn is_indentation_error(&self) -> bool {
match self {
Self::CompileError {
is_indentation_error,
..
} => *is_indentation_error,
_ => false,
}
}
}
impl From<koto_runtime::Error> for Error {
fn from(error: koto_runtime::Error) -> Self {
use koto_runtime::ErrorKind as RuntimeError;
match error.error {
RuntimeError::CompileError(error) => Self::from(error),
_ => Self::StringError(error.to_string()),
}
}
}
impl From<koto_bytecode::ModuleLoaderError> for Error {
fn from(error: koto_bytecode::ModuleLoaderError) -> Self {
Self::CompileError {
error: error.to_string(),
is_indentation_error: error.is_indentation_error(),
}
}
}
pub type Result<T> = std::result::Result<T, Error>;