Error handling refactoring

- Replace .ok_or_else() and .map_err() with anyhow::Context where possible.
- Use .context() to check Option for None when it's an error
- Resultify Chatlist.get_chat_id()
- Add useful .context() to some errors
- IMAP error handling cleanup
This commit is contained in:
link2xt
2022-01-05 01:51:11 +00:00
parent 29c58efeb3
commit bfa641cea8
24 changed files with 252 additions and 283 deletions

View File

@@ -5,7 +5,7 @@ use std::ffi::OsString;
use std::ops::Deref;
use std::time::{Instant, SystemTime};
use anyhow::{bail, ensure, Result};
use anyhow::{bail, ensure, Context as _, Result};
use async_std::{
channel::{self, Receiver, Sender},
path::{Path, PathBuf},
@@ -155,7 +155,10 @@ impl Context {
let ctx = Context {
inner: Arc::new(inner),
};
ctx.sql.open(&ctx, &ctx.dbfile, false).await?;
ctx.sql
.open(&ctx, &ctx.dbfile, false)
.await
.context("failed to open SQL database")?;
Ok(ctx)
}