use std::error::Error;
use std::fmt;
use tidepool_repr::DataConId;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum BridgeError {
UnknownDataCon(DataConId),
UnknownDataConName(String),
ArityMismatch {
con: DataConId,
expected: usize,
got: usize,
},
TypeMismatch {
expected: String,
got: String,
},
UnsupportedType(String),
InternalError(String),
}
impl fmt::Display for BridgeError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
BridgeError::UnknownDataCon(id) => write!(f, "Unknown DataConId: {:?}", id),
BridgeError::UnknownDataConName(name) => write!(f, "Unknown DataCon name: {}", name),
BridgeError::ArityMismatch { con, expected, got } => {
write!(
f,
"Arity mismatch for DataCon {:?}: expected {}, got {}",
con, expected, got
)
}
BridgeError::TypeMismatch { expected, got } => {
write!(f, "Type mismatch: expected {}, got {}", expected, got)
}
BridgeError::UnsupportedType(ty) => write!(f, "Unsupported type: {}", ty),
BridgeError::InternalError(msg) => write!(f, "Internal error: {}", msg),
}
}
}
impl Error for BridgeError {}