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::streamtyped::StreamTypedError;
8
9/// Errors that can happen when working with message table data
10#[derive(Debug)]
11pub enum MessageError {
12    /// Message has no text content
13    NoText,
14    /// Error occurred when parsing with the `StreamTyped` parser
15    StreamTypedParseError(StreamTypedError),
16    /// Timestamp value is invalid or out of range
17    InvalidTimestamp(i64),
18}
19
20impl Display for MessageError {
21    fn fmt(&self, fmt: &mut Formatter<'_>) -> Result {
22        match self {
23            MessageError::NoText => write!(fmt, "Message has no text!"),
24            MessageError::StreamTypedParseError(why) => {
25                write!(
26                    fmt,
27                    "Failed to parse attributedBody with legacy parser: {why}"
28                )
29            }
30            MessageError::InvalidTimestamp(when) => {
31                write!(fmt, "Timestamp is invalid: {when}")
32            }
33        }
34    }
35}
36
37impl From<StreamTypedError> for MessageError {
38    fn from(err: StreamTypedError) -> Self {
39        MessageError::StreamTypedParseError(err)
40    }
41}