imessage_database/error/
message.rs1use std::fmt::{Display, Formatter, Result};
6
7use crate::error::plist::PlistParseError;
8
9#[derive(Debug)]
11pub enum MessageError {
12 PlistParseError(PlistParseError),
14 InvalidTimestamp(i64),
16}
17
18impl Display for MessageError {
19 fn fmt(&self, fmt: &mut Formatter<'_>) -> Result {
20 match self {
21 MessageError::InvalidTimestamp(when) => {
22 write!(fmt, "Timestamp is invalid: {when}")
23 }
24 MessageError::PlistParseError(why) => {
25 write!(fmt, "Failed to parse property list: {why}")
26 }
27 }
28 }
29}
30
31impl std::error::Error for MessageError {
32 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
33 match self {
34 MessageError::PlistParseError(e) => Some(e),
35 _ => None,
36 }
37 }
38}
39
40impl From<PlistParseError> for MessageError {
41 fn from(err: PlistParseError) -> Self {
42 MessageError::PlistParseError(err)
43 }
44}