use std::fmt;
#[derive(Debug, Clone, PartialEq)]
pub enum IteratorStackError {
InvalidChainSyntax { expression: String, reason: String },
IncompatibleFanoutDepths {
field1: String,
depth1: usize,
field2: String,
depth2: usize,
},
CartesianFanoutError {
field1: String,
branch1: String,
field2: String,
branch2: String,
},
ReducerRequired {
field: String,
current_depth: usize,
max_depth: usize,
},
InvalidIteratorChain { chain: String, reason: String },
AmbiguousFanoutDifferentBranches { branches: Vec<String> },
MaxDepthExceeded {
current_depth: usize,
max_depth: usize,
},
FieldAlignmentError { field: String, reason: String },
ExecutionError { message: String },
}
impl fmt::Display for IteratorStackError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
IteratorStackError::InvalidChainSyntax { expression, reason } => {
write!(
f,
"Invalid chain syntax in expression '{}': {}",
expression, reason
)
}
IteratorStackError::IncompatibleFanoutDepths {
field1,
depth1,
field2,
depth2,
} => {
write!(
f,
"Incompatible fan-out depths: field '{}' at depth {} vs field '{}' at depth {}",
field1, depth1, field2, depth2
)
}
IteratorStackError::CartesianFanoutError {
field1,
branch1,
field2,
branch2,
} => {
write!(
f,
"Cartesian fan-out error: field '{}' on branch '{}' vs field '{}' on branch '{}'",
field1, branch1, field2, branch2
)
}
IteratorStackError::ReducerRequired {
field,
current_depth,
max_depth,
} => {
write!(
f,
"Field '{}' at depth {} exceeds max depth {} and requires a reducer",
field, current_depth, max_depth
)
}
IteratorStackError::InvalidIteratorChain { chain, reason } => {
write!(f, "Invalid iterator chain '{}': {}", chain, reason)
}
IteratorStackError::AmbiguousFanoutDifferentBranches { branches } => {
write!(
f,
"Ambiguous fan-out on different branches: {}",
branches.join(", ")
)
}
IteratorStackError::MaxDepthExceeded {
current_depth,
max_depth,
} => {
write!(
f,
"Iterator depth {} exceeds maximum allowed depth {}",
current_depth, max_depth
)
}
IteratorStackError::FieldAlignmentError { field, reason } => {
write!(f, "Field alignment error for '{}': {}", field, reason)
}
IteratorStackError::ExecutionError { message } => {
write!(f, "Execution error: {}", message)
}
}
}
}
impl std::error::Error for IteratorStackError {}
pub type IteratorStackResult<T> = Result<T, IteratorStackError>;
pub mod constants {
pub const MAX_ITERATOR_DEPTH: usize = 10;
pub const MAX_FIELDS_PER_SCHEMA: usize = 100;
pub const MAX_CHAIN_EXPRESSION_LENGTH: usize = 1000;
}