Remove ContextError type

Using anyhow instead.
This commit is contained in:
link2xt
2023-01-28 11:01:30 +00:00
parent ba3e4c5dff
commit c911f1262a

View File

@@ -9,7 +9,7 @@ use std::path::{Path, PathBuf};
use std::sync::Arc;
use std::time::{Duration, Instant, SystemTime};
use anyhow::{ensure, Result};
use anyhow::{bail, ensure, Result};
use async_channel::{self as channel, Receiver, Sender};
use ratelimit::Ratelimit;
use tokio::sync::{Mutex, RwLock};
@@ -149,26 +149,17 @@ impl ContextBuilder {
}
/// Opens the [`Context`].
pub async fn open(self) -> Result<Context, ContextError> {
pub async fn open(self) -> Result<Context> {
let context =
Context::new_closed(&self.dbfile, self.id, self.events, self.stock_strings).await?;
let password = self.password.unwrap_or_default();
match context.open(password).await? {
true => Ok(context),
false => Err(ContextError::DatabaseEncrypted),
false => bail!("database could not be decrypted, incorrect or missing password"),
}
}
}
#[non_exhaustive]
#[derive(Debug, thiserror::Error)]
pub enum ContextError {
#[error("database could not be decrypted, incorrect or missing password")]
DatabaseEncrypted,
#[error("failed to open context")]
Other(#[from] anyhow::Error),
}
/// The context for a single DeltaChat account.
///
/// This contains all the state for a single DeltaChat account, including background tasks