use std::fmt;
#[cfg(feature = "parser")]
use crate::parser::ParseError;
#[derive(Debug, Clone, PartialEq)]
pub enum DnfError {
FieldNotFound(Box<str>),
TypeMismatch {
field: Box<str>,
expected: Box<str>,
actual: Box<str>,
position: Option<usize>, },
InvalidOp { field: Box<str>, operator: Box<str> },
UnknownField {
field_name: Box<str>,
position: usize,
},
InvalidMapTarget {
field_name: Box<str>,
field_kind: crate::FieldKind,
},
UnregisteredCustomOp { operator_name: Box<str> },
#[cfg(feature = "parser")]
ParseError(ParseError),
}
impl fmt::Display for DnfError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
DnfError::FieldNotFound(field) => {
write!(f, "Field '{}' not found", field)
}
DnfError::TypeMismatch {
field,
expected,
actual,
position,
} => match position {
Some(pos) => write!(
f,
"Type mismatch for field '{}' at position {}: expected {}, got {}",
field, pos, expected, actual
),
None => write!(
f,
"Type mismatch for field '{}': expected {}, got {}",
field, expected, actual
),
},
DnfError::InvalidOp { field, operator } => {
write!(f, "Invalid operator '{}' for field '{}'", operator, field)
}
DnfError::UnknownField {
field_name,
position,
} => write!(f, "Unknown field '{}' at position {}", field_name, position),
DnfError::InvalidMapTarget {
field_name,
field_kind,
} => write!(
f,
"Map target (AtKey/Keys/Values/Entries) used with non-map field '{}' (kind: {:?})",
field_name, field_kind
),
DnfError::UnregisteredCustomOp { operator_name } => write!(
f,
"Custom operator '{}' is not registered in the operator registry",
operator_name
),
#[cfg(feature = "parser")]
DnfError::ParseError(err) => write!(f, "{}", err),
}
}
}
impl std::error::Error for DnfError {}