imessage_database/error/
plist.rs

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