Skip to main content

ecr_store/
error.rs

1use std::path::PathBuf;
2
3pub type Result<T> = std::result::Result<T, Error>;
4
5#[derive(Debug, thiserror::Error)]
6pub enum Error {
7    #[error("no {kind} configuration found (looked in: {})", .searched.iter().map(|p| p.display().to_string()).collect::<Vec<_>>().join(", "))]
8    ConfigNotFound {
9        kind: &'static str,
10        searched: Vec<PathBuf>,
11    },
12
13    #[error("{path}: {message}")]
14    ConfigParse { path: PathBuf, message: String },
15
16    #[error("notmuch database.path is not set in {path}")]
17    NoDatabasePath { path: PathBuf },
18
19    #[error("maildir root {path} does not exist")]
20    MaildirMissing { path: PathBuf },
21
22    #[error("`{tool}` was not found on PATH")]
23    ToolMissing { tool: &'static str },
24
25    #[error("`{tool}` failed: {stderr}")]
26    ToolFailed { tool: &'static str, stderr: String },
27
28    #[error("no message with id {id}")]
29    MessageNotFound { id: String },
30
31    #[error("no part {part} in message {id}")]
32    PartNotFound { id: String, part: u32 },
33
34    #[error("could not parse message {id}: {message}")]
35    MessageParse { id: String, message: String },
36
37    #[error("invalid tag {tag:?}: {reason}")]
38    InvalidTag { tag: String, reason: &'static str },
39
40    #[error("no msmtp account named {account}")]
41    UnknownSendAccount { account: String },
42
43    #[error("cannot send this draft: {reason}")]
44    InvalidDraft { reason: String },
45
46    #[error("{path:?} is not a file ecr will read: {reason}")]
47    UnsafePath { path: String, reason: &'static str },
48
49    #[error("{0}")]
50    Oauth(String),
51
52    #[error("mail index: {0}")]
53    Index(String),
54
55    #[error(transparent)]
56    Io(#[from] std::io::Error),
57}
58
59/// The index is a cache, so nothing it does is ever reported to a reader: the
60/// error exists to be logged and fallen back from. Flattening SQLite's own
61/// error into a string keeps rusqlite out of this crate's public surface.
62impl From<rusqlite::Error> for Error {
63    fn from(err: rusqlite::Error) -> Self {
64        Error::Index(err.to_string())
65    }
66}