imessage_database/error/
plist.rs1use crabstep::error::TypedStreamError;
6
7use crate::error::digital_touch::DigitalTouchError;
8use crate::error::handwriting::HandwritingError;
9use std::fmt::{Display, Formatter, Result};
10
11#[derive(Debug)]
13pub enum PlistParseError {
14 MissingKey(String),
16 NoValueAtIndex(usize),
18 InvalidType(String, String),
20 InvalidTypeIndex(usize, String),
22 InvalidDictionarySize(usize, usize),
24 UidOutOfRange(u64),
26 NoPayload,
28 WrongMessageType,
30 InvalidEditedMessage(String),
32 TypedStreamError(TypedStreamError),
34 HandwritingError(HandwritingError),
36 DigitalTouchError(DigitalTouchError),
38 PollError,
40 RecursionLimit,
42}
43
44impl Display for PlistParseError {
45 fn fmt(&self, fmt: &mut Formatter<'_>) -> Result {
46 match self {
47 PlistParseError::MissingKey(key) => write!(fmt, "Expected key {key}, found nothing!"),
48 PlistParseError::NoValueAtIndex(idx) => {
49 write!(fmt, "Payload referenced index {idx}, but there is no data!")
50 }
51 PlistParseError::InvalidType(key, value) => {
52 write!(fmt, "Invalid data found at {key}, expected {value}")
53 }
54 PlistParseError::InvalidTypeIndex(idx, value) => {
55 write!(
56 fmt,
57 "Invalid data found at object index {idx}, expected {value}"
58 )
59 }
60 PlistParseError::InvalidDictionarySize(a, b) => write!(
61 fmt,
62 "Invalid dictionary size, found {a} keys and {b} values"
63 ),
64 PlistParseError::UidOutOfRange(uid) => {
65 write!(fmt, "UID value {uid} cannot be used as an object index")
66 }
67 PlistParseError::NoPayload => write!(fmt, "Unable to acquire payload data!"),
68 PlistParseError::WrongMessageType => write!(fmt, "Message is not an app message!"),
69 PlistParseError::InvalidEditedMessage(message) => {
70 write!(fmt, "Unable to parse message from binary data: {message}")
71 }
72 PlistParseError::HandwritingError(why) => write!(fmt, "{why}"),
73 PlistParseError::DigitalTouchError(why) => write!(fmt, "{why}"),
74 PlistParseError::TypedStreamError(typed_stream_error) => {
75 write!(fmt, "TypedStream error: {typed_stream_error}")
76 }
77 PlistParseError::PollError => write!(fmt, "Unable to parse Poll Message!"),
78 PlistParseError::RecursionLimit => write!(
79 fmt,
80 "Exceeded maximum depth while resolving UID references; the archive may contain a reference cycle"
81 ),
82 }
83 }
84}
85
86impl std::error::Error for PlistParseError {
87 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
88 match self {
89 PlistParseError::TypedStreamError(e) => Some(e),
90 PlistParseError::HandwritingError(e) => Some(e),
91 PlistParseError::DigitalTouchError(e) => Some(e),
92 _ => None,
93 }
94 }
95}
96
97impl From<TypedStreamError> for PlistParseError {
98 fn from(error: TypedStreamError) -> Self {
99 PlistParseError::TypedStreamError(error)
100 }
101}