use std::fmt::{Display, Formatter, Result};
#[derive(Debug)]
pub enum DigitalTouchError {
ProtobufError(protobuf::Error),
UnknownDigitalTouchKind(i32),
ArraysDoNotMatch(&'static str, usize, &'static str, usize),
InvalidStrokesLength(usize, usize),
ArchiveError(plist::Error),
}
impl std::error::Error for DigitalTouchError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
DigitalTouchError::ProtobufError(why) => Some(why),
DigitalTouchError::ArchiveError(why) => Some(why),
_ => None,
}
}
}
impl Display for DigitalTouchError {
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result {
match self {
DigitalTouchError::ProtobufError(why) => {
write!(fmt, "failed to parse digital touch protobuf: {why}")
}
DigitalTouchError::UnknownDigitalTouchKind(kind) => {
write!(fmt, "unknown digital touch kind: {kind}")
}
DigitalTouchError::ArraysDoNotMatch(n1, v1, n2, v2) => {
write!(fmt, "mismatched array lengths: {n1} ({v1}) != {n2} ({v2})")
}
DigitalTouchError::InvalidStrokesLength(needed, available) => {
write!(
fmt,
"stroke needs {needed} bytes but only {available} remain"
)
}
DigitalTouchError::ArchiveError(why) => {
write!(fmt, "failed to read digital touch media archive: {why}")
}
}
}
}