imessage_database/error/
digital_touch.rs1use std::fmt::{Display, Formatter, Result};
6
7#[derive(Debug)]
9pub enum DigitalTouchError {
10 ProtobufError(protobuf::Error),
12 UnknownDigitalTouchKind(i32),
14 ArraysDoNotMatch(&'static str, usize, &'static str, usize),
17 InvalidStrokesLength(usize, usize),
19 ArchiveError(plist::Error),
21}
22
23impl std::error::Error for DigitalTouchError {
24 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
25 match self {
26 DigitalTouchError::ProtobufError(why) => Some(why),
27 DigitalTouchError::ArchiveError(why) => Some(why),
28 _ => None,
29 }
30 }
31}
32
33impl Display for DigitalTouchError {
34 fn fmt(&self, fmt: &mut Formatter<'_>) -> Result {
35 match self {
36 DigitalTouchError::ProtobufError(why) => {
37 write!(fmt, "failed to parse digital touch protobuf: {why}")
38 }
39 DigitalTouchError::UnknownDigitalTouchKind(kind) => {
40 write!(fmt, "unknown digital touch kind: {kind}")
41 }
42 DigitalTouchError::ArraysDoNotMatch(n1, v1, n2, v2) => {
43 write!(fmt, "mismatched array lengths: {n1} ({v1}) != {n2} ({v2})")
44 }
45 DigitalTouchError::InvalidStrokesLength(needed, available) => {
46 write!(
47 fmt,
48 "stroke needs {needed} bytes but only {available} remain"
49 )
50 }
51 DigitalTouchError::ArchiveError(why) => {
52 write!(fmt, "failed to read digital touch media archive: {why}")
53 }
54 }
55 }
56}