rustfmt changes

sieve
Manos Pitsidianakis 2022-12-27 18:40:26 +02:00
parent 5443b7e8f3
commit de2f46fe61
13 changed files with 40 additions and 76 deletions

View File

@ -40,7 +40,7 @@ pub use self::imap::ImapType;
#[cfg(feature = "imap_backend")] #[cfg(feature = "imap_backend")]
pub use self::nntp::NntpType; pub use self::nntp::NntpType;
use crate::conf::AccountSettings; use crate::conf::AccountSettings;
use crate::error::{ErrorKind, Error, Result}; use crate::error::{Error, ErrorKind, Result};
#[cfg(feature = "maildir_backend")] #[cfg(feature = "maildir_backend")]
use self::maildir::MaildirType; use self::maildir::MaildirType;

View File

@ -1245,9 +1245,7 @@ impl MailBackend for ImapType {
)); ));
} }
} }
Err(Error::new( Err(Error::new(String::from_utf8_lossy(&response).to_string()))
String::from_utf8_lossy(&response).to_string(),
))
})) }))
} }
} }

View File

@ -240,10 +240,7 @@ impl ImapStream {
let addr = if let Ok(a) = lookup_ipv4(path, server_conf.server_port) { let addr = if let Ok(a) = lookup_ipv4(path, server_conf.server_port) {
a a
} else { } else {
return Err(Error::new(format!( return Err(Error::new(format!("Could not lookup address {}", &path)));
"Could not lookup address {}",
&path
)));
}; };
AsyncWrapper::new(Connection::Tcp( AsyncWrapper::new(Connection::Tcp(
if let Some(timeout) = server_conf.timeout { if let Some(timeout) = server_conf.timeout {

View File

@ -82,11 +82,10 @@ impl BackendOp for ImapOp {
); );
let mut results = protocol_parser::fetch_responses(&response)?.1; let mut results = protocol_parser::fetch_responses(&response)?.1;
if results.len() != 1 { if results.len() != 1 {
return Err(Error::new(format!( return Err(
"Invalid/unexpected response: {:?}", Error::new(format!("Invalid/unexpected response: {:?}", response))
response .set_summary(format!("message with UID {} was not found?", uid)),
)) );
.set_summary(format!("message with UID {} was not found?", uid)));
} }
let FetchResponse { let FetchResponse {
uid: _uid, uid: _uid,
@ -147,11 +146,10 @@ impl BackendOp for ImapOp {
debug!(String::from_utf8_lossy(&response)); debug!(String::from_utf8_lossy(&response));
/* TODO: Trigger cache invalidation here. */ /* TODO: Trigger cache invalidation here. */
debug!("message with UID {} was not found", uid); debug!("message with UID {} was not found", uid);
return Err(Error::new(format!( return Err(
"Invalid/unexpected response: {:?}", Error::new(format!("Invalid/unexpected response: {:?}", response))
response .set_summary(format!("message with UID {} was not found?", uid)),
)) );
.set_summary(format!("message with UID {} was not found?", uid)));
} }
let (_uid, (_flags, _)) = v[0]; let (_uid, (_flags, _)) = v[0];
assert_eq!(_uid, uid); assert_eq!(_uid, uid);

View File

@ -28,7 +28,7 @@ use super::{MaildirMailbox, MaildirOp, MaildirPathTrait};
use crate::backends::{RefreshEventKind::*, *}; use crate::backends::{RefreshEventKind::*, *};
use crate::conf::AccountSettings; use crate::conf::AccountSettings;
use crate::email::{Envelope, EnvelopeHash, Flag}; use crate::email::{Envelope, EnvelopeHash, Flag};
use crate::error::{ErrorKind, Error, Result}; use crate::error::{Error, ErrorKind, Result};
use crate::shellexpand::ShellExpandTrait; use crate::shellexpand::ShellExpandTrait;
use crate::Collection; use crate::Collection;
use futures::prelude::Stream; use futures::prelude::Stream;

View File

@ -126,7 +126,7 @@ use crate::collection::Collection;
use crate::conf::AccountSettings; use crate::conf::AccountSettings;
use crate::email::parser::BytesExt; use crate::email::parser::BytesExt;
use crate::email::*; use crate::email::*;
use crate::error::{ErrorKind, Error, Result}; use crate::error::{Error, ErrorKind, Result};
use crate::get_path_hash; use crate::get_path_hash;
use crate::shellexpand::ShellExpandTrait; use crate::shellexpand::ShellExpandTrait;
use nom::bytes::complete::tag; use nom::bytes::complete::tag;
@ -1244,10 +1244,8 @@ impl MailBackend for MboxType {
_query: crate::search::Query, _query: crate::search::Query,
_mailbox_hash: Option<MailboxHash>, _mailbox_hash: Option<MailboxHash>,
) -> ResultFuture<SmallVec<[EnvelopeHash; 512]>> { ) -> ResultFuture<SmallVec<[EnvelopeHash; 512]>> {
Err( Err(Error::new("Search is unimplemented for the mbox backend.")
Error::new("Search is unimplemented for the mbox backend.") .set_kind(ErrorKind::NotImplemented))
.set_kind(ErrorKind::NotImplemented),
)
} }
fn create_mailbox( fn create_mailbox(

View File

@ -270,10 +270,9 @@ pub fn lookup_ipv4(host: &str, port: u16) -> crate::Result<std::net::SocketAddr>
} }
Err( Err(
crate::error::Error::new(format!("Could not lookup address {}:{}", host, port)) crate::error::Error::new(format!("Could not lookup address {}:{}", host, port)).set_kind(
.set_kind(crate::error::ErrorKind::Network( crate::error::ErrorKind::Network(crate::error::NetworkErrorKind::HostLookupFailed),
crate::error::NetworkErrorKind::HostLookupFailed, ),
)),
) )
} }
@ -284,8 +283,10 @@ pub async fn timeout<O>(dur: Option<Duration>, f: impl Future<Output = O>) -> cr
if let Some(dur) = dur { if let Some(dur) = dur {
match future::select(f, smol::Timer::after(dur)).await { match future::select(f, smol::Timer::after(dur)).await {
Either::Left((out, _)) => Ok(out), Either::Left((out, _)) => Ok(out),
Either::Right(_) => Err(crate::error::Error::new("Timed out.") Either::Right(_) => {
.set_kind(crate::error::ErrorKind::Timeout)), Err(crate::error::Error::new("Timed out.")
.set_kind(crate::error::ErrorKind::Timeout))
}
} }
} else { } else {
Ok(f.await) Ok(f.await)

View File

@ -23,7 +23,7 @@ use crate::email::{
pgp::{DecryptionMetadata, Recipient}, pgp::{DecryptionMetadata, Recipient},
Address, Address,
}; };
use crate::error::{ErrorKind, IntoError, Error, Result, ResultIntoError}; use crate::error::{Error, ErrorKind, IntoError, Result, ResultIntoError};
use futures::FutureExt; use futures::FutureExt;
use serde::{ use serde::{
de::{self, Deserialize}, de::{self, Deserialize},
@ -259,9 +259,8 @@ impl Context {
} }
let ret = Context { let ret = Context {
inner: Arc::new(ContextInner { inner: Arc::new(ContextInner {
inner: core::ptr::NonNull::new(ptr).ok_or_else(|| { inner: core::ptr::NonNull::new(ptr)
Error::new("Could not use libgpgme").set_kind(ErrorKind::Bug) .ok_or_else(|| Error::new("Could not use libgpgme").set_kind(ErrorKind::Bug))?,
})?,
lib, lib,
}), }),
io_state, io_state,
@ -714,9 +713,8 @@ impl Context {
let mut sig = Data { let mut sig = Data {
lib: self.inner.lib.clone(), lib: self.inner.lib.clone(),
kind: DataKind::Memory, kind: DataKind::Memory,
inner: core::ptr::NonNull::new(sig).ok_or_else(|| { inner: core::ptr::NonNull::new(sig)
Error::new("internal libgpgme error").set_kind(ErrorKind::Bug) .ok_or_else(|| Error::new("internal libgpgme error").set_kind(ErrorKind::Bug))?,
})?,
}; };
let io_state = self.io_state.clone(); let io_state = self.io_state.clone();
@ -818,9 +816,8 @@ impl Context {
let mut plain = Data { let mut plain = Data {
lib: self.inner.lib.clone(), lib: self.inner.lib.clone(),
kind: DataKind::Memory, kind: DataKind::Memory,
inner: core::ptr::NonNull::new(plain).ok_or_else(|| { inner: core::ptr::NonNull::new(plain)
Error::new("internal libgpgme error").set_kind(ErrorKind::Bug) .ok_or_else(|| Error::new("internal libgpgme error").set_kind(ErrorKind::Bug))?,
})?,
}; };
let ctx = self.inner.clone(); let ctx = self.inner.clone();
@ -1030,9 +1027,8 @@ impl Context {
let mut cipher = Data { let mut cipher = Data {
lib: self.inner.lib.clone(), lib: self.inner.lib.clone(),
kind: DataKind::Memory, kind: DataKind::Memory,
inner: core::ptr::NonNull::new(cipher).ok_or_else(|| { inner: core::ptr::NonNull::new(cipher)
Error::new("internal libgpgme error").set_kind(ErrorKind::Bug) .ok_or_else(|| Error::new("internal libgpgme error").set_kind(ErrorKind::Bug))?,
})?,
}; };
let ctx = self.inner.clone(); let ctx = self.inner.clone();

View File

@ -148,10 +148,7 @@ impl Component for KeySelection {
} }
} else { } else {
*self = KeySelection::Error { *self = KeySelection::Error {
err: Error::new(format!( err: Error::new(format!("No keys found for {}.", pattern)),
"No keys found for {}.",
pattern
)),
id, id,
} }
} }

View File

@ -401,11 +401,7 @@ This is required so that you don't accidentally start meli and find out later th
let mut file = OpenOptions::new().append(true).open(&path)?; let mut file = OpenOptions::new().append(true).open(&path)?;
file.write_all("[composing]\nsend_mail = 'false'\n".as_bytes()) file.write_all("[composing]\nsend_mail = 'false'\n".as_bytes())
.map_err(|err| { .map_err(|err| {
Error::new(format!( Error::new(format!("Could not append to {}: {}", path.display(), err))
"Could not append to {}: {}",
path.display(),
err
))
})?; })?;
return FileSettings::validate(path, interactive, clear_extras); return FileSettings::validate(path, interactive, clear_extras);
} }

View File

@ -28,7 +28,7 @@ use crate::jobs::{JobExecutor, JobId, JoinHandle};
use indexmap::IndexMap; use indexmap::IndexMap;
use melib::backends::*; use melib::backends::*;
use melib::email::*; use melib::email::*;
use melib::error::{ErrorKind, Error, Result}; use melib::error::{Error, ErrorKind, Result};
use melib::text_processing::GlobMatch; use melib::text_processing::GlobMatch;
use melib::thread::{SortField, SortOrder, Threads}; use melib::thread::{SortField, SortOrder, Threads};
use melib::AddressBook; use melib::AddressBook;
@ -1394,9 +1394,7 @@ impl Account {
) )
}; };
melib::log(&error_message, melib::LoggingLevel::ERROR); melib::log(&error_message, melib::LoggingLevel::ERROR);
return Err( return Err(Error::new(error_message).set_summary("Message not sent."));
Error::new(error_message).set_summary("Message not sent.")
);
} }
Ok(()) Ok(())
} }

View File

@ -1212,23 +1212,14 @@ impl Themes {
Themes::validate_keys(name, t, &hash_set)?; Themes::validate_keys(name, t, &hash_set)?;
} }
if let Err(err) = is_cyclic(&self.light) { if let Err(err) = is_cyclic(&self.light) {
return Err(Error::new(format!( return Err(Error::new(format!("light theme contains a cycle: {}", err)));
"light theme contains a cycle: {}",
err
)));
} }
if let Err(err) = is_cyclic(&self.dark) { if let Err(err) = is_cyclic(&self.dark) {
return Err(Error::new(format!( return Err(Error::new(format!("dark theme contains a cycle: {}", err)));
"dark theme contains a cycle: {}",
err
)));
} }
for (k, t) in self.other_themes.iter() { for (k, t) in self.other_themes.iter() {
if let Err(err) = is_cyclic(t) { if let Err(err) = is_cyclic(t) {
return Err(Error::new(format!( return Err(Error::new(format!("{} theme contains a cycle: {}", k, err)));
"{} theme contains a cycle: {}",
k, err
)));
} }
} }
Ok(()) Ok(())

View File

@ -78,10 +78,7 @@ fn parse_manpage(src: &str) -> Result<ManPages> {
"meli.7" | "guide" => Ok(ManPages::Guide), "meli.7" | "guide" => Ok(ManPages::Guide),
"meli.conf" | "meli.conf.5" | "conf" | "config" | "configuration" => Ok(ManPages::Conf), "meli.conf" | "meli.conf.5" | "conf" | "config" | "configuration" => Ok(ManPages::Conf),
"meli-themes" | "meli-themes.5" | "themes" | "theming" | "theme" => Ok(ManPages::Themes), "meli-themes" | "meli-themes.5" | "themes" | "theming" | "theme" => Ok(ManPages::Themes),
_ => Err(Error::new(format!( _ => Err(Error::new(format!("Invalid documentation page: {}", src))),
"Invalid documentation page: {}",
src
))),
} }
} }
@ -284,10 +281,7 @@ fn run_app(opt: Opt) -> Result<()> {
path.display() path.display()
))); )));
} else if !path.is_file() { } else if !path.is_file() {
return Err(Error::new(format!( return Err(Error::new(format!("`{}` is a directory", path.display())));
"`{}` is a directory",
path.display()
)));
} }
} }
None => {} None => {}