Skip to main content

dead_man_switch/
error.rs

1pub use lettre::address::AddressError;
2use lettre::{
3    error::Error as LettreError,
4    message::header::ContentTypeErr,
5    transport::smtp::{self},
6};
7use thiserror::Error;
8use toml::{de::Error as DerTomlError, ser::Error as SerTomlError};
9
10/// Home Directory Errors
11#[derive(Error, Debug)]
12pub enum HomeDirError {
13    /// IO operations on home directory.
14    #[error(transparent)]
15    Io(#[from] std::io::Error),
16
17    /// Failed to find home directory.
18    #[error("Failed to find home directory")]
19    HomeDirNotFound,
20}
21
22/// Configuration errors
23#[derive(Error, Debug)]
24pub enum ConfigError {
25    /// IO operations on config module.
26    #[error(transparent)]
27    Io(#[from] std::io::Error),
28
29    /// TOML serialization.
30    #[error(transparent)]
31    TomlSerialization(#[from] SerTomlError),
32
33    /// TOML deserialization.
34    #[error(transparent)]
35    TomlDeserialization(#[from] DerTomlError),
36
37    /// Attachment not found.
38    #[error("Attachment not found")]
39    AttachmentNotFound,
40
41    /// Config directory errors.
42    #[error(transparent)]
43    ConfigFile(#[from] HomeDirError),
44}
45
46// Timer errors
47#[derive(Error, Debug)]
48pub enum TimerError {
49    /// IO operations on timer module.
50    #[error(transparent)]
51    Io(#[from] std::io::Error),
52
53    /// TOML serialization.
54    #[error(transparent)]
55    TomlSerialization(#[from] SerTomlError),
56
57    /// TOML deserialization.
58    #[error(transparent)]
59    TomlDeserialization(#[from] DerTomlError),
60
61    /// Config error
62    #[error(transparent)]
63    Config(#[from] ConfigError),
64
65    /// Config directory errors.
66    #[error(transparent)]
67    ConfigFile(#[from] HomeDirError),
68
69    /// SystemTime error
70    #[error("System time error: {0}")]
71    SystemTime(#[from] std::time::SystemTimeError),
72}
73
74/// Errors that can occur when sending an email.
75#[derive(Error, Debug)]
76pub enum EmailError {
77    /// TLS error when sending the email.
78    #[error(transparent)]
79    TlsError(#[from] smtp::Error),
80
81    /// Error when parsing email addresses.
82    #[error(transparent)]
83    EmailError(#[from] AddressError),
84
85    /// Error when building the email.
86    #[error(transparent)]
87    BuilderError(#[from] LettreError),
88
89    /// Error when reading the attachment.
90    #[error(transparent)]
91    IoError(#[from] std::io::Error),
92
93    /// Error when determining the content type of the attachment.
94    #[error(transparent)]
95    InvalidContent(#[from] ContentTypeErr),
96
97    /// Error when determining the content type of the attachment.
98    #[error(transparent)]
99    AttachmentPath(#[from] ConfigError),
100
101    /// Timeout error
102    #[error("timeout")]
103    Timeout,
104
105    /// Disconnected error
106    #[error("disconnected")]
107    Disconnected,
108
109    #[error("smtp error: {0}")]
110    SmtpError(smtp::Error),
111}
112
113/// TUI Error type.
114#[derive(Error, Debug)]
115pub enum TuiError {
116    /// IO Error.
117    #[error(transparent)]
118    Io(#[from] std::io::Error),
119
120    /// [`ConfigError`] blanket error conversion.
121    #[error(transparent)]
122    Config(#[from] ConfigError),
123
124    /// [`EmailError`] blanket error conversion.
125    #[error(transparent)]
126    Email(#[from] EmailError),
127
128    /// [`TimerError`] blanket error conversion.
129    #[error(transparent)]
130    Timer(#[from] TimerError),
131}