use std::fmt::{self, Debug, Display};
use crate::Type;
use super::Value;
#[derive(Debug)]
pub enum Error {
WrongParameters {
expected: Type,
got: Value,
},
NonStructRootValue,
Fmt(fmt::Error),
Escape(String),
Function(Box<maybe_sync::dyn_maybe_send_sync!(std::error::Error)>),
}
impl Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::WrongParameters { expected, got } => {
write!(f, "Wrong parameters; expected {expected} but got {got:?}")
}
Self::NonStructRootValue => write!(
f,
"Root value needs to be a struct but received non struct value instead"
),
Self::Escape(err) => write!(f, "Error escaping: {err}"),
Self::Fmt(err) => write!(f, "Failed to write: {err}"),
Self::Function(err) => write!(f, "Function returned error: {err}"),
}
}
}
impl std::error::Error for Error {}
pub(crate) const WRONG_TYPE_MESSAGE: &str =
"this should have been caught by type checking or a function misbehaved";