use std::{error, fmt, string::FromUtf8Error};
#[derive(Debug)]
#[non_exhaustive]
pub enum DataError {
BrokenCompression(Compression, Box<dyn std::error::Error + Send + Sync>),
BrokenFbxFooter,
InvalidArrayAttributeEncoding(u32),
InvalidAttributeTypeCode(u8),
InvalidNodeNameEncoding(FromUtf8Error),
NodeAttributeError,
NodeLengthMismatch(u64, Option<u64>),
UnexpectedAttribute(String, String),
}
impl error::Error for DataError {
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
match self {
DataError::BrokenCompression(_, e) => Some(e.as_ref()),
DataError::InvalidNodeNameEncoding(e) => Some(e),
_ => None,
}
}
}
impl fmt::Display for DataError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
DataError::BrokenFbxFooter => write!(f, "FBX footer is broken"),
DataError::BrokenCompression(codec, e) => write!(
f,
"Data with broken compression (codec={:?}): {:?}",
codec, e
),
DataError::InvalidArrayAttributeEncoding(encoding) => {
write!(f, "Unknown array attribute encoding: got {:?}", encoding)
}
DataError::InvalidAttributeTypeCode(code) => {
write!(f, "Invalid node attribute type code: {:?}", code)
}
DataError::InvalidNodeNameEncoding(e) => {
write!(f, "Invalid node name encoding: {:?}", e)
}
DataError::NodeAttributeError => {
write!(f, "Some error occured while reading node attributes")
}
DataError::NodeLengthMismatch(expected, got) => write!(
f,
"Node ends with unexpected position: expected {}, got {:?}",
expected, got
),
DataError::UnexpectedAttribute(expected, got) => write!(
f,
"Unexpected attribute value or type: expected {}, got {}",
expected, got
),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Compression {
Zlib,
}