imessage_database/error/
message.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*!
 Errors that can happen when parsing message data.
*/

use std::fmt::{Display, Formatter, Result};

use crate::error::{plist::PlistParseError, streamtyped::StreamTypedError};

use super::typedstream::TypedStreamError;

/// Errors that can happen when working with message table data
#[derive(Debug)]
pub enum MessageError {
    MissingData,
    NoText,
    StreamTypedParseError(StreamTypedError),
    TypedStreamParseError(TypedStreamError),
    PlistParseError(PlistParseError),
    InvalidTimestamp(i64),
}

impl Display for MessageError {
    fn fmt(&self, fmt: &mut Formatter<'_>) -> Result {
        match self {
            MessageError::MissingData => write!(fmt, "No attributedBody found!"),
            MessageError::NoText => write!(fmt, "Message has no text!"),
            MessageError::StreamTypedParseError(why) => {
                write!(
                    fmt,
                    "Failed to parse attributedBody with legacy parser: {why}"
                )
            }
            MessageError::TypedStreamParseError(why) => {
                write!(fmt, "Failed to parse attributedBody: {why}")
            }
            MessageError::PlistParseError(why) => {
                write!(fmt, "Failed to parse plist data: {why}")
            }
            MessageError::InvalidTimestamp(when) => {
                write!(fmt, "Timestamp is invalid: {when}")
            }
        }
    }
}