use std::fmt;
#[derive(Debug)]
pub enum DynamicError {
InvalidTypeName(String),
FieldNotFound(String),
EmptyPath,
NotAMessage(String),
TypeMismatch { path: String, expected: String },
IndexOutOfBounds(usize),
SerializationError(String),
DeserializationError(String),
SchemaLoadError { package: String, source: String },
RegistryLockPoisoned,
SchemaNotFound(String),
ServiceTimeout { node: String, service: String },
MissingNodeIdentity { topic: String },
InvalidDefaultValue { field: String, reason: String },
BoundExceeded { max: usize, actual: usize },
}
impl fmt::Display for DynamicError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
DynamicError::InvalidTypeName(name) => {
write!(
f,
"Invalid type name '{}': expected format 'package/msg/Name'",
name
)
}
DynamicError::FieldNotFound(name) => {
write!(f, "Field '{}' not found in message schema", name)
}
DynamicError::EmptyPath => {
write!(f, "Empty path provided for field access")
}
DynamicError::NotAMessage(name) => {
write!(
f,
"Field '{}' is not a message type, cannot access nested fields",
name
)
}
DynamicError::TypeMismatch { path, expected } => {
write!(
f,
"Type mismatch at '{}': expected type '{}'",
path, expected
)
}
DynamicError::IndexOutOfBounds(idx) => {
write!(f, "Field index {} is out of bounds", idx)
}
DynamicError::SerializationError(msg) => {
write!(f, "CDR serialization error: {}", msg)
}
DynamicError::DeserializationError(msg) => {
write!(f, "CDR deserialization error: {}", msg)
}
DynamicError::SchemaLoadError { package, source } => {
write!(
f,
"Failed to load schema for package '{}': {}",
package, source
)
}
DynamicError::RegistryLockPoisoned => {
write!(f, "Schema registry lock was poisoned")
}
DynamicError::SchemaNotFound(name) => {
write!(f, "Schema '{}' not found in registry", name)
}
DynamicError::ServiceTimeout { node, service } => {
write!(
f,
"type description service timed out: no response from node '{}' on service '{}'",
node, service
)
}
DynamicError::MissingNodeIdentity { topic } => {
write!(
f,
"automatic schema discovery for topic '{}' requires publisher node identity, which is unavailable from this backend/discovery format",
topic
)
}
DynamicError::InvalidDefaultValue { field, reason } => {
write!(f, "Invalid default value for field '{}': {}", field, reason)
}
DynamicError::BoundExceeded { max, actual } => {
write!(
f,
"Bounded type exceeded maximum size: max={}, actual={}",
max, actual
)
}
}
}
}
impl std::error::Error for DynamicError {}
impl From<hiroz_cdr::Error> for DynamicError {
fn from(e: hiroz_cdr::Error) -> Self {
DynamicError::DeserializationError(e.to_string())
}
}