use std::{error, fmt};
use fbxcel::{low::v7400::AttributeType, tree::v7400::NodeId};
use crate::v7400::{connection::ConnectionIndex, LoadError};
#[derive(Debug, Clone)]
pub(crate) enum ConnectionError {
MissingNodeTypes(NodeId, ConnectionIndex),
InvalidNodeTypesType(NodeId, ConnectionIndex, AttributeType),
InvalidNodeTypesValue(NodeId, ConnectionIndex, String),
MissingSourceId(NodeId, ConnectionIndex),
InvalidSourceIdType(NodeId, ConnectionIndex, AttributeType),
MissingDestinationId(NodeId, ConnectionIndex),
InvalidDestinationIdType(NodeId, ConnectionIndex, AttributeType),
InvalidLabelType(NodeId, ConnectionIndex, AttributeType),
}
impl fmt::Display for ConnectionError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
ConnectionError::MissingNodeTypes(node, conn_index) => write!(
f,
"Connection node types not found: node={:?}, conn_index={:?}",
node, conn_index
),
ConnectionError::InvalidNodeTypesType(node, conn_index, ty) => write!(
f,
"Invalid node types value type for node={:?}, conn_index={:?}: \
expected string, got {:?}",
node, conn_index, ty
),
ConnectionError::InvalidNodeTypesValue(node, conn_index, val) => write!(
f,
"Invalid node types value for node={:?}, conn_index={:?}: got {:?}",
node, conn_index, val
),
ConnectionError::MissingSourceId(node, conn_index) => write!(
f,
"Connection source object ID not found: node={:?}, conn_index={:?}",
node, conn_index
),
ConnectionError::InvalidSourceIdType(node, conn_index, ty) => write!(
f,
"Invalid source object ID value type for node={:?}, conn_index={:?}: \
expected `i64`, got {:?}",
node, conn_index, ty
),
ConnectionError::MissingDestinationId(node, conn_index) => write!(
f,
"Connection destination object ID not found: node={:?}, conn_index={:?}",
node, conn_index
),
ConnectionError::InvalidDestinationIdType(node, conn_index, ty) => write!(
f,
"Invalid destination object ID value type for node={:?}, conn_index={:?}: \
expected `i64`, got {:?}",
node, conn_index, ty
),
ConnectionError::InvalidLabelType(node, conn_index, ty) => write!(
f,
"Invalid connection label value type for node={:?}, conn_index={:?}: \
expected string, got {:?}",
node, conn_index, ty
),
}
}
}
impl error::Error for ConnectionError {}
impl From<ConnectionError> for LoadError {
fn from(e: ConnectionError) -> Self {
Self::new(e)
}
}