use std::error::Error as StdError;
use std::fmt::{Display, Formatter};
use typed_builder::TypedBuilder;
#[derive(Clone, Eq, PartialEq, TypedBuilder, Debug)]
pub struct EvaluationError {
pub code: EvaluationErrorCode,
#[builder(default, setter(strip_option, into))]
pub message: Option<String>,
}
#[derive(Clone, Eq, PartialEq, Debug)]
pub enum EvaluationErrorCode {
ProviderNotReady,
FlagNotFound,
ParseError,
TypeMismatch,
TargetingKeyMissing,
InvalidContext,
General(String),
}
impl Display for EvaluationErrorCode {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let code = match self {
Self::ProviderNotReady => "PROVIDER_NOT_READY",
Self::FlagNotFound => "FLAG_NOT_FOUND",
Self::ParseError => "PARSE_ERROR",
Self::TypeMismatch => "TYPE_MISMATCH",
Self::TargetingKeyMissing => "TARGETING_KEY_MISSING",
Self::InvalidContext => "INVALID_CONTEXT",
Self::General(message) => message,
};
write!(f, "{code}")
}
}
impl StdError for EvaluationErrorCode {}