imessage_database/error/
message.rs

1/*!
2 Errors that can happen when parsing message data.
3*/
4
5use std::fmt::{Display, Formatter, Result};
6
7use crate::error::{plist::PlistParseError, streamtyped::StreamTypedError};
8
9use super::typedstream::TypedStreamError;
10
11/// Errors that can happen when working with message table data
12#[derive(Debug)]
13pub enum MessageError {
14    MissingData,
15    NoText,
16    StreamTypedParseError(StreamTypedError),
17    TypedStreamParseError(TypedStreamError),
18    PlistParseError(PlistParseError),
19    InvalidTimestamp(i64),
20}
21
22impl Display for MessageError {
23    fn fmt(&self, fmt: &mut Formatter<'_>) -> Result {
24        match self {
25            MessageError::MissingData => write!(fmt, "No attributedBody found!"),
26            MessageError::NoText => write!(fmt, "Message has no text!"),
27            MessageError::StreamTypedParseError(why) => {
28                write!(
29                    fmt,
30                    "Failed to parse attributedBody with legacy parser: {why}"
31                )
32            }
33            MessageError::TypedStreamParseError(why) => {
34                write!(fmt, "Failed to parse attributedBody: {why}")
35            }
36            MessageError::PlistParseError(why) => {
37                write!(fmt, "Failed to parse plist data: {why}")
38            }
39            MessageError::InvalidTimestamp(when) => {
40                write!(fmt, "Timestamp is invalid: {when}")
41            }
42        }
43    }
44}