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