imessage_database/error/
message.rs1use std::fmt::{Display, Formatter, Result};
6
7use crabstep::error::TypedStreamError;
8
9use crate::error::{plist::PlistParseError, streamtyped::StreamTypedError};
10
11#[derive(Debug)]
13pub enum MessageError {
14 NoText,
16 StreamTypedParseError(StreamTypedError),
18 TypedStreamError(TypedStreamError),
20 PlistParseError(PlistParseError),
22 InvalidTimestamp(i64),
24}
25
26impl Display for MessageError {
27 fn fmt(&self, fmt: &mut Formatter<'_>) -> Result {
28 match self {
29 MessageError::NoText => write!(fmt, "Message has no text!"),
30 MessageError::StreamTypedParseError(why) => {
31 write!(
32 fmt,
33 "Failed to parse attributedBody with legacy parser: {why}"
34 )
35 }
36 MessageError::InvalidTimestamp(when) => {
37 write!(fmt, "Timestamp is invalid: {when}")
38 }
39 MessageError::TypedStreamError(typed_stream_error) => {
40 write!(
41 fmt,
42 "Failed to deserialize typed stream: {typed_stream_error}"
43 )
44 }
45 MessageError::PlistParseError(why) => {
46 write!(fmt, "Failed to parse property list: {why}")
47 }
48 }
49 }
50}
51
52impl From<StreamTypedError> for MessageError {
53 fn from(err: StreamTypedError) -> Self {
54 MessageError::StreamTypedParseError(err)
55 }
56}
57
58impl From<TypedStreamError> for MessageError {
59 fn from(err: TypedStreamError) -> Self {
60 MessageError::TypedStreamError(err)
61 }
62}
63
64impl From<PlistParseError> for MessageError {
65 fn from(err: PlistParseError) -> Self {
66 MessageError::PlistParseError(err)
67 }
68}