Skip to main content

imessage_database/error/
attachment.rs

1/*!
2 Errors that can happen when parsing attachment data.
3*/
4
5use std::{
6    fmt::{Display, Formatter, Result},
7    io::Error,
8};
9
10/// Errors that can happen when working with attachment table data
11#[derive(Debug)]
12pub enum AttachmentError {
13    /// The attachment file exists but could not be read due to an IO error
14    Unreadable(String, Error),
15}
16
17impl std::error::Error for AttachmentError {
18    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
19        match self {
20            AttachmentError::Unreadable(_, e) => Some(e),
21        }
22    }
23}
24
25impl Display for AttachmentError {
26    fn fmt(&self, fmt: &mut Formatter<'_>) -> Result {
27        match self {
28            AttachmentError::Unreadable(path, why) => {
29                write!(fmt, "Unable to read file at {path}: {why}")
30            }
31        }
32    }
33}