imessage_database/error/
plist.rs

1/*!
2 Errors that can happen when parsing plist data.
3*/
4
5use crate::error::handwriting::HandwritingError;
6use crate::error::streamtyped::StreamTypedError;
7use std::fmt::{Display, Formatter, Result};
8
9/// Errors that can happen when parsing the plist data stored in the `payload_data` field
10#[derive(Debug)]
11pub enum PlistParseError {
12    /// Expected key was not found in the plist data
13    MissingKey(String),
14    /// No value was found at the specified index
15    NoValueAtIndex(usize),
16    /// Value had an incorrect type for the specified key
17    InvalidType(String, String),
18    /// Value had an incorrect type at the specified index
19    InvalidTypeIndex(usize, String),
20    /// Dictionary has mismatched number of keys and values
21    InvalidDictionarySize(usize, usize),
22    /// No payload data was found
23    NoPayload,
24    /// Message is not of the expected type
25    WrongMessageType,
26    /// Could not parse an edited message
27    InvalidEditedMessage(String),
28    /// Error from stream typed parsing
29    StreamTypedError(StreamTypedError),
30    /// Error from handwriting data parsing
31    HandwritingError(HandwritingError),
32    /// Error parsing Digital Touch message
33    DigitalTouchError,
34}
35
36impl Display for PlistParseError {
37    fn fmt(&self, fmt: &mut Formatter<'_>) -> Result {
38        match self {
39            PlistParseError::MissingKey(key) => write!(fmt, "Expected key {key}, found nothing!"),
40            PlistParseError::NoValueAtIndex(idx) => {
41                write!(fmt, "Payload referenced index {idx}, but there is no data!")
42            }
43            PlistParseError::InvalidType(key, value) => {
44                write!(fmt, "Invalid data found at {key}, expected {value}")
45            }
46            PlistParseError::InvalidTypeIndex(idx, value) => {
47                write!(
48                    fmt,
49                    "Invalid data found at object index {idx}, expected {value}"
50                )
51            }
52            PlistParseError::InvalidDictionarySize(a, b) => write!(
53                fmt,
54                "Invalid dictionary size, found {a} keys and {b} values"
55            ),
56            PlistParseError::NoPayload => write!(fmt, "Unable to acquire payload data!"),
57            PlistParseError::WrongMessageType => write!(fmt, "Message is not an app message!"),
58            PlistParseError::InvalidEditedMessage(message) => {
59                write!(fmt, "Unable to parse message from binary data: {message}")
60            }
61            PlistParseError::StreamTypedError(why) => write!(fmt, "{why}"),
62            PlistParseError::HandwritingError(why) => write!(fmt, "{why}"),
63            PlistParseError::DigitalTouchError => {
64                write!(fmt, "Unable to parse Digital Touch Message!")
65            }
66        }
67    }
68}