melib/error: Add kinds: NotImplemented, NotSupported, OSError

pull/144/head
Manos Pitsidianakis 2021-09-05 12:39:15 +03:00
parent 72a2ba20dc
commit 07e166e1fb
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
4 changed files with 20 additions and 10 deletions

View File

@ -50,7 +50,7 @@ pub use self::imap::ImapType;
#[cfg(feature = "imap_backend")]
pub use self::nntp::NntpType;
use crate::conf::AccountSettings;
use crate::error::{MeliError, Result};
use crate::error::{ErrorKind, MeliError, Result};
#[cfg(feature = "maildir_backend")]
use self::maildir::MaildirType;
@ -360,14 +360,14 @@ pub trait MailBackend: ::std::fmt::Debug + Send + Sync {
&mut self,
_path: String,
) -> ResultFuture<(MailboxHash, HashMap<MailboxHash, Mailbox>)> {
Err(MeliError::new("Unimplemented."))
Err(MeliError::new("Unimplemented.").set_kind(ErrorKind::NotImplemented))
}
fn delete_mailbox(
&mut self,
_mailbox_hash: MailboxHash,
) -> ResultFuture<HashMap<MailboxHash, Mailbox>> {
Err(MeliError::new("Unimplemented."))
Err(MeliError::new("Unimplemented.").set_kind(ErrorKind::NotImplemented))
}
fn set_mailbox_subscription(
@ -375,7 +375,7 @@ pub trait MailBackend: ::std::fmt::Debug + Send + Sync {
_mailbox_hash: MailboxHash,
_val: bool,
) -> ResultFuture<()> {
Err(MeliError::new("Unimplemented."))
Err(MeliError::new("Unimplemented.").set_kind(ErrorKind::NotImplemented))
}
fn rename_mailbox(
@ -383,7 +383,7 @@ pub trait MailBackend: ::std::fmt::Debug + Send + Sync {
_mailbox_hash: MailboxHash,
_new_path: String,
) -> ResultFuture<Mailbox> {
Err(MeliError::new("Unimplemented."))
Err(MeliError::new("Unimplemented.").set_kind(ErrorKind::NotImplemented))
}
fn set_mailbox_permissions(
@ -391,7 +391,7 @@ pub trait MailBackend: ::std::fmt::Debug + Send + Sync {
_mailbox_hash: MailboxHash,
_val: MailboxPermissions,
) -> ResultFuture<()> {
Err(MeliError::new("Unimplemented."))
Err(MeliError::new("Unimplemented.").set_kind(ErrorKind::NotImplemented))
}
fn search(
@ -399,7 +399,7 @@ pub trait MailBackend: ::std::fmt::Debug + Send + Sync {
_query: crate::search::Query,
_mailbox_hash: Option<MailboxHash>,
) -> ResultFuture<SmallVec<[EnvelopeHash; 512]>> {
Err(MeliError::new("Unimplemented."))
Err(MeliError::new("Unimplemented.").set_kind(ErrorKind::NotImplemented))
}
fn submit(
@ -408,7 +408,7 @@ pub trait MailBackend: ::std::fmt::Debug + Send + Sync {
_mailbox_hash: Option<MailboxHash>,
_flags: Option<Flag>,
) -> ResultFuture<()> {
Err(MeliError::new("Not supported in this backend."))
Err(MeliError::new("Not supported in this backend.").set_kind(ErrorKind::NotSupported))
}
}

View File

@ -352,7 +352,7 @@ impl MailBackend for NntpType {
}
fn watch(&self) -> ResultFuture<()> {
Err(MeliError::new("Unimplemented."))
Err(MeliError::new("Unimplemented.").set_kind(ErrorKind::NotImplemented))
}
fn operation(&self, env_hash: EnvelopeHash) -> Result<Box<dyn BackendOp>> {

View File

@ -42,6 +42,9 @@ pub enum ErrorKind {
Bug,
Network,
Timeout,
OSError,
NotImplemented,
NotSupported,
}
impl fmt::Display for ErrorKind {
@ -56,6 +59,9 @@ impl fmt::Display for ErrorKind {
ErrorKind::Bug => "Bug, please report this!",
ErrorKind::Network => "Network",
ErrorKind::Timeout => "Timeout",
ErrorKind::OSError => "OS Error",
ErrorKind::NotImplemented => "Not implemented",
ErrorKind::NotSupported => "Not supported",
}
)
}
@ -208,6 +214,7 @@ impl From<io::Error> for MeliError {
MeliError::new(kind.to_string())
.set_summary(format!("{:?}", kind.kind()))
.set_source(Some(Arc::new(kind)))
.set_kind(ErrorKind::OSError)
}
}

View File

@ -28,7 +28,7 @@ use crate::jobs::{JobExecutor, JobId, JoinHandle};
use indexmap::IndexMap;
use melib::backends::*;
use melib::email::*;
use melib::error::{MeliError, Result};
use melib::error::{ErrorKind, MeliError, Result};
use melib::text_processing::GlobMatch;
use melib::thread::{SortField, SortOrder, Threads};
use melib::AddressBook;
@ -1078,6 +1078,9 @@ impl Account {
self.active_jobs
.insert(handle.job_id, JobRequest::Watch { handle });
}
Err(e)
if e.kind == ErrorKind::NotSupported || e.kind == ErrorKind::NotImplemented => {
}
Err(e) => {
self.sender
.send(ThreadEvent::UIEvent(UIEvent::StatusEvent(