use std::fmt;
use super::{OptionScopeId, OptionValue, scope::OptionScope};
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum OptionError {
NotFound(String),
AlreadyExists(String),
ValidationFailed {
name: String,
reason: String,
},
TypeMismatch {
name: String,
expected: &'static str,
got: &'static str,
},
AliasConflict(String),
ScopeMismatch {
name: String,
option_scope: OptionScope,
requested: OptionScopeId,
},
}
impl fmt::Display for OptionError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::NotFound(name) => write!(f, "option not found: {name}"),
Self::AlreadyExists(name) => write!(f, "option already exists: {name}"),
Self::ValidationFailed { name, reason } => {
write!(f, "validation failed for '{name}': {reason}")
}
Self::TypeMismatch {
name,
expected,
got,
} => {
write!(f, "type mismatch for '{name}': expected {expected}, got {got}")
}
Self::AliasConflict(alias) => {
write!(f, "alias conflicts with existing name: {alias}")
}
Self::ScopeMismatch {
name,
option_scope,
requested,
} => {
write!(
f,
"scope mismatch for '{name}': option is {option_scope}, requested {requested}"
)
}
}
}
}
impl std::error::Error for OptionError {}
#[derive(Debug, Clone)]
pub struct SetResult {
pub old_value: Option<OptionValue>,
pub new_value: OptionValue,
}