chore: moving to color_eyre

This commit is contained in:
Justin Miller
2021-10-10 19:26:34 -06:00
committed by Aiden McClelland
parent 36bae894a9
commit 81164f974f
38 changed files with 380 additions and 180 deletions

View File

@@ -2,8 +2,8 @@ use std::collections::BTreeMap;
use std::path::Path;
use std::str::FromStr;
use anyhow::anyhow;
use clap::ArgMatches;
use color_eyre::eyre::eyre;
use indexmap::IndexSet;
use patch_db::HasModel;
use rpc_toolkit::command;
@@ -131,7 +131,7 @@ impl Action {
true,
)
.await?
.map_err(|e| Error::new(anyhow!("{}", e.1), crate::ErrorKind::Action))
.map_err(|e| Error::new(eyre!("{}", e.1), crate::ErrorKind::Action))
}
}
@@ -228,7 +228,7 @@ pub async fn action(
.await
} else {
Err(Error::new(
anyhow!("Action not found in manifest"),
eyre!("Action not found in manifest"),
crate::ErrorKind::NotFound,
))
}

View File

@@ -1,10 +1,10 @@
use std::collections::BTreeMap;
use std::marker::PhantomData;
use anyhow::anyhow;
use basic_cookies::Cookie;
use chrono::{DateTime, Utc};
use clap::ArgMatches;
use color_eyre::eyre::eyre;
use http::header::COOKIE;
use http::HeaderValue;
use rpc_toolkit::command;
@@ -90,10 +90,7 @@ pub async fn login(
.password;
ensure_code!(
argon2::verify_encoded(&pw_hash, password.as_bytes()).map_err(|_| {
Error::new(
anyhow!("Password Incorrect"),
crate::ErrorKind::Authorization,
)
Error::new(eyre!("Password Incorrect"), crate::ErrorKind::Authorization)
})?,
crate::ErrorKind::Authorization,
"Password Incorrect"

View File

@@ -1,4 +1,4 @@
use anyhow::anyhow;
use color_eyre::eyre::eyre;
use patch_db::HasModel;
use regex::NoExpand;
use serde::{Deserialize, Serialize};
@@ -36,7 +36,7 @@ impl BackupActions {
false,
)
.await?
.map_err(|e| anyhow!("{}", e.1))
.map_err(|e| eyre!("{}", e.1))
.with_kind(crate::ErrorKind::Backup)?;
Ok(NoOutput)
}
@@ -61,7 +61,7 @@ impl BackupActions {
false,
)
.await?
.map_err(|e| anyhow!("{}", e.1))
.map_err(|e| eyre!("{}", e.1))
.with_kind(crate::ErrorKind::Restore)?;
Ok(NoOutput)
}

View File

@@ -1,7 +1,7 @@
use std::collections::BTreeMap;
use std::time::Duration;
use anyhow::anyhow;
use color_eyre::eyre::eyre;
use embassy::context::{DiagnosticContext, RpcContext};
use embassy::db::subscribe;
use embassy::middleware::auth::auth;
@@ -218,20 +218,22 @@ async fn inner_main(
futures::try_join!(
server.map_err(|e| Error::new(e, ErrorKind::Network)),
revision_cache_task.map_err(|e| Error::new(
anyhow!("{}", e).context("Revision Cache daemon panicked!"),
eyre!("{}", e).wrap_err("Revision Cache daemon panicked!"),
ErrorKind::Unknown
)),
ws_server.map_err(|e| Error::new(e, ErrorKind::Network)),
status_daemon.map_err(|e| Error::new(
e.context("Status Sync daemon panicked!"),
e.wrap_err("Status Sync daemon panicked!"),
ErrorKind::Unknown
)),
health_daemon.map_err(|e| Error::new(
e.context("Health Check daemon panicked!"),
e.wrap_err("Health Check daemon panicked!"),
ErrorKind::Unknown
)),
tor_health_daemon.map_err(|e| Error::new(
e.wrap_err("Tor Health daemon panicked!"),
ErrorKind::Unknown
)),
tor_health_daemon
.map_err(|e| Error::new(e.context("Tor Health daemon panicked!"), ErrorKind::Unknown)),
)?;
rpc_ctx.managers.empty().await?;

View File

@@ -1,6 +1,6 @@
use std::collections::{BTreeMap, BTreeSet};
use anyhow::anyhow;
use color_eyre::eyre::eyre;
use nix::sys::signal::Signal;
use patch_db::HasModel;
use serde::{Deserialize, Serialize};
@@ -47,7 +47,7 @@ impl ConfigActions {
)
.await
.and_then(|res| {
res.map_err(|e| Error::new(anyhow!("{}", e.1), crate::ErrorKind::ConfigGen))
res.map_err(|e| Error::new(eyre!("{}", e.1), crate::ErrorKind::ConfigGen))
})
}
@@ -74,7 +74,7 @@ impl ConfigActions {
.await
.and_then(|res| {
res.map_err(|e| {
Error::new(anyhow!("{}", e.1), crate::ErrorKind::ConfigRulesViolation)
Error::new(eyre!("{}", e.1), crate::ErrorKind::ConfigRulesViolation)
})
})?;
Ok(SetResult {

View File

@@ -1,8 +1,8 @@
use std::collections::{BTreeMap, BTreeSet};
use std::time::Duration;
use anyhow::anyhow;
use bollard::container::KillContainerOptions;
use color_eyre::eyre::eyre;
use futures::future::{BoxFuture, FutureExt};
use indexmap::IndexSet;
use itertools::Itertools;
@@ -167,7 +167,7 @@ pub async fn get(
.get(&mut db, true)
.await?
.to_owned()
.ok_or_else(|| Error::new(anyhow!("{} has no config", id), crate::ErrorKind::NotFound))?;
.ok_or_else(|| Error::new(eyre!("{} has no config", id), crate::ErrorKind::NotFound))?;
let version = pkg_model
.clone()
.manifest()
@@ -302,9 +302,7 @@ pub fn configure<'a, Db: DbHandle>(
.get(db, true)
.await?
.to_owned()
.ok_or_else(|| {
Error::new(anyhow!("{} has no config", id), crate::ErrorKind::NotFound)
})?;
.ok_or_else(|| Error::new(eyre!("{} has no config", id), crate::ErrorKind::NotFound))?;
let version = pkg_model.clone().manifest().version().get(db, true).await?;
let dependencies = pkg_model
.clone()

View File

@@ -4,8 +4,8 @@ use std::net::{Ipv4Addr, SocketAddr};
use std::path::{Path, PathBuf};
use std::sync::Arc;
use anyhow::anyhow;
use clap::ArgMatches;
use color_eyre::eyre::eyre;
use cookie_store::CookieStore;
use reqwest::Proxy;
use reqwest_cookie_store::CookieStoreMutex;
@@ -92,7 +92,7 @@ impl CliContext {
});
let cookie_store = Arc::new(CookieStoreMutex::new(if cookie_path.exists() {
CookieStore::load_json(BufReader::new(File::open(&cookie_path)?))
.map_err(|e| anyhow!("{}", e))
.map_err(|e| eyre!("{}", e))
.with_kind(crate::ErrorKind::Deserialization)?
} else {
CookieStore::default()

View File

@@ -3,8 +3,8 @@ use std::io::Read;
use std::path::{Path, PathBuf};
use std::sync::Arc;
use anyhow::anyhow;
use clap::ArgMatches;
use color_eyre::eyre::eyre;
use rpc_toolkit::Context;
use serde::Deserialize;
@@ -48,7 +48,7 @@ impl SdkContext {
/// BLOCKING
pub fn developer_key(&self) -> Result<ed25519_dalek::Keypair, Error> {
if !self.developer_key_path.exists() {
return Err(Error::new(anyhow!("Developer Key does not exist! Please run `embassy-sdk init` before running this command."), crate::ErrorKind::Uninitialized));
return Err(Error::new(eyre!("Developer Key does not exist! Please run `embassy-sdk init` before running this command."), crate::ErrorKind::Uninitialized));
}
let mut keypair_buf = [0; ed25519_dalek::KEYPAIR_LENGTH];
File::open(&self.developer_key_path)?.read_exact(&mut keypair_buf)?;

View File

@@ -1,7 +1,7 @@
use std::collections::BTreeMap;
use anyhow::anyhow;
use chrono::Utc;
use color_eyre::eyre::eyre;
use patch_db::DbHandle;
use rpc_toolkit::command;
@@ -54,9 +54,7 @@ pub async fn start(
.managers
.get(&(id.clone(), version))
.await
.ok_or_else(|| {
Error::new(anyhow!("Manager not found"), crate::ErrorKind::Docker)
})?,
.ok_or_else(|| Error::new(eyre!("Manager not found"), crate::ErrorKind::Docker))?,
)
.await?;
status.save(&mut tx).await?;

View File

@@ -6,7 +6,7 @@ use std::future::Future;
use std::sync::Arc;
use std::time::Duration;
use anyhow::anyhow;
use color_eyre::eyre::eyre;
use futures::{FutureExt, SinkExt, StreamExt};
use patch_db::json_ptr::JsonPointer;
use patch_db::{Dump, Revision};
@@ -67,7 +67,7 @@ async fn ws_handler<
.into_iter()
.find(|c| c.get_name() == "session")
.ok_or_else(|| {
Error::new(anyhow!("UNAUTHORIZED"), crate::ErrorKind::Authorization)
Error::new(eyre!("UNAUTHORIZED"), crate::ErrorKind::Authorization)
})?;
if let Err(e) =
crate::middleware::auth::is_authed(&ctx, &hash_token(id.get_value())).await

View File

@@ -1,6 +1,6 @@
use std::collections::BTreeMap;
use anyhow::anyhow;
use color_eyre::eyre::eyre;
use emver::VersionRange;
use futures::future::BoxFuture;
use futures::FutureExt;
@@ -439,7 +439,7 @@ impl DependencyConfig {
Some(old),
)
.await?
.map_err(|e| Error::new(anyhow!("{}", e.1), crate::ErrorKind::AutoConfigure))
.map_err(|e| Error::new(eyre!("{}", e.1), crate::ErrorKind::AutoConfigure))
}
}
@@ -590,7 +590,7 @@ pub fn break_transitive<'a, Db: DbHandle>(
.into_owned()
.ok_or_else(|| {
Error::new(
anyhow!("{} not in listed dependencies", dependency),
eyre!("{} not in listed dependencies", dependency),
crate::ErrorKind::Database,
)
})?

View File

@@ -1,7 +1,7 @@
use std::collections::BTreeMap;
use std::path::{Path, PathBuf};
use anyhow::anyhow;
use color_eyre::eyre::{self, eyre};
use futures::TryStreamExt;
use indexmap::IndexSet;
use regex::Regex;
@@ -54,7 +54,7 @@ pub async fn get_vendor<P: AsRef<Path>>(path: P) -> Result<Option<String>, Error
Path::new(SYS_BLOCK_PATH)
.join(path.as_ref().strip_prefix("/dev").map_err(|_| {
Error::new(
anyhow!("not a canonical block device"),
eyre!("not a canonical block device"),
crate::ErrorKind::BlockDevice,
)
})?)
@@ -74,7 +74,7 @@ pub async fn get_model<P: AsRef<Path>>(path: P) -> Result<Option<String>, Error>
Path::new(SYS_BLOCK_PATH)
.join(path.as_ref().strip_prefix("/dev").map_err(|_| {
Error::new(
anyhow!("not a canonical block device"),
eyre!("not a canonical block device"),
crate::ErrorKind::BlockDevice,
)
})?)
@@ -141,7 +141,7 @@ pub async fn list() -> Result<Vec<DiskInfo>, Error> {
)
.map_err(|e| {
Error::new(
anyhow::Error::from(e).context(DISK_PATH),
eyre::Error::from(e).wrap_err(DISK_PATH),
crate::ErrorKind::Filesystem,
)
})
@@ -312,7 +312,7 @@ pub async fn mount_encfs<P0: AsRef<Path>, P1: AsRef<Path>>(
let mut err = String::new();
stderr.read_to_string(&mut err).await?;
if !encfs.wait().await?.success() {
Err(Error::new(anyhow!("{}", err), crate::ErrorKind::Filesystem))
Err(Error::new(eyre!("{}", err), crate::ErrorKind::Filesystem))
} else {
Ok(())
}
@@ -350,7 +350,7 @@ pub async fn bind<P0: AsRef<Path>, P1: AsRef<Path>>(
.await
.map_err(|e| {
Error::new(
e.source.context(format!(
e.source.wrap_err(format!(
"Binding {} to {}",
src.as_ref().display(),
dst.as_ref().display(),

View File

@@ -1,6 +1,6 @@
use std::fmt::Display;
use anyhow::anyhow;
use color_eyre::eyre::eyre;
use patch_db::Revision;
use rpc_toolkit::yajrc::RpcError;
@@ -128,7 +128,7 @@ impl Display for ErrorKind {
#[derive(Debug)]
pub struct Error {
pub source: anyhow::Error,
pub source: color_eyre::eyre::Error,
pub kind: ErrorKind,
pub revision: Option<Revision>,
}
@@ -138,7 +138,7 @@ impl Display for Error {
}
}
impl Error {
pub fn new<E: Into<anyhow::Error>>(source: E, kind: ErrorKind) -> Self {
pub fn new<E: Into<color_eyre::eyre::Error>>(source: E, kind: ErrorKind) -> Self {
Error {
source: source.into(),
kind,
@@ -203,7 +203,7 @@ impl From<bollard::errors::Error> for Error {
}
impl From<torut::control::ConnError> for Error {
fn from(e: torut::control::ConnError) -> Self {
Error::new(anyhow!("{:?}", e), ErrorKind::Tor)
Error::new(eyre!("{:?}", e), ErrorKind::Tor)
}
}
impl From<std::net::AddrParseError> for Error {
@@ -213,7 +213,7 @@ impl From<std::net::AddrParseError> for Error {
}
impl From<openssl::error::ErrorStack> for Error {
fn from(e: openssl::error::ErrorStack) -> Self {
Error::new(anyhow!("OpenSSL ERROR:\n{}", e), ErrorKind::OpenSsl)
Error::new(eyre!("OpenSSL ERROR:\n{}", e), ErrorKind::OpenSsl)
}
}
impl From<Error> for RpcError {
@@ -250,7 +250,7 @@ where
}
impl<T, E> ResultExt<T, E> for Result<T, E>
where
anyhow::Error: From<E>,
color_eyre::eyre::Error: From<E>,
{
fn with_kind(self, kind: ErrorKind) -> Result<T, Error> {
self.map_err(|e| Error {
@@ -266,9 +266,9 @@ where
) -> Result<T, Error> {
self.map_err(|e| {
let (kind, ctx) = f(&e);
let source = anyhow::Error::from(e);
let source = color_eyre::eyre::Error::from(e);
let ctx = format!("{}: {}", ctx, source);
let source = source.context(ctx);
let source = source.wrap_err(ctx);
Error {
kind,
source: source.into(),
@@ -282,7 +282,7 @@ where
macro_rules! ensure_code {
($x:expr, $c:expr, $fmt:expr $(, $arg:expr)*) => {
if !($x) {
return Err(crate::Error::new(anyhow!($fmt, $($arg, )*), $c));
return Err(crate::Error::new(eyre!($fmt, $($arg, )*), $c));
}
};
}

View File

@@ -5,7 +5,7 @@ use std::process::Stdio;
use std::sync::atomic::Ordering;
use std::sync::Arc;
use anyhow::anyhow;
use color_eyre::eyre::{self, eyre};
use emver::VersionRange;
use futures::TryStreamExt;
use http::StatusCode;
@@ -102,7 +102,7 @@ pub async fn install(
}
_ => {
return Err(Error::new(
anyhow!("Cannot install over a package in a transient state"),
eyre!("Cannot install over a package in a transient state"),
crate::ErrorKind::InvalidRequest,
))
}
@@ -165,7 +165,7 @@ pub async fn uninstall_impl(ctx: RpcContext, id: PackageId) -> Result<WithRevisi
}) => (manifest, static_files, installed),
_ => {
return Err(Error::new(
anyhow!("Package is not installed."),
eyre!("Package is not installed."),
crate::ErrorKind::NotFound,
));
}
@@ -466,19 +466,19 @@ pub async fn install_s9pk<R: AsyncRead + AsyncSeek + Unpin>(
.spawn()?;
let tee_in = tee.stdin.take().ok_or_else(|| {
Error::new(
anyhow!("Could not write to stdin of tee"),
eyre!("Could not write to stdin of tee"),
crate::ErrorKind::Docker,
)
})?;
let mut tee_out = tee.stdout.take().ok_or_else(|| {
Error::new(
anyhow!("Could not read from stdout of tee"),
eyre!("Could not read from stdout of tee"),
crate::ErrorKind::Docker,
)
})?;
let load_in = load.stdin.take().ok_or_else(|| {
Error::new(
anyhow!("Could not write to stdin of docker load"),
eyre!("Could not write to stdin of docker load"),
crate::ErrorKind::Docker,
)
})?;
@@ -490,7 +490,7 @@ pub async fn install_s9pk<R: AsyncRead + AsyncSeek + Unpin>(
let res = load.wait_with_output().await?;
if !res.status.success() {
Err(Error::new(
anyhow!(
eyre!(
"{}",
String::from_utf8(res.stderr)
.unwrap_or_else(|e| format!("Could not parse stderr: {}", e))
@@ -764,7 +764,7 @@ pub async fn load_images<P: AsRef<Path>>(datadir: P) -> Result<(), Error> {
ReadDirStream::new(tokio::fs::read_dir(&docker_dir).await?)
.map_err(|e| {
Error::new(
anyhow::Error::from(e).context(format!("{:?}", &docker_dir)),
eyre::Report::from(e).wrap_err(format!("{:?}", &docker_dir)),
crate::ErrorKind::Filesystem,
)
})
@@ -772,7 +772,7 @@ pub async fn load_images<P: AsRef<Path>>(datadir: P) -> Result<(), Error> {
ReadDirStream::new(tokio::fs::read_dir(pkg_id.path()).await?)
.map_err(|e| {
Error::new(
anyhow::Error::from(e).context(pkg_id.path().display().to_string()),
eyre::Report::from(e).wrap_err(pkg_id.path().display().to_string()),
crate::ErrorKind::Filesystem,
)
})
@@ -784,7 +784,7 @@ pub async fn load_images<P: AsRef<Path>>(datadir: P) -> Result<(), Error> {
.spawn()?;
let load_in = load.stdin.take().ok_or_else(|| {
Error::new(
anyhow!("Could not write to stdin of docker load"),
eyre!("Could not write to stdin of docker load"),
crate::ErrorKind::Docker,
)
})?;
@@ -793,7 +793,7 @@ pub async fn load_images<P: AsRef<Path>>(datadir: P) -> Result<(), Error> {
let res = load.wait_with_output().await?;
if !res.status.success() {
Err(Error::new(
anyhow!(
eyre!(
"{}",
String::from_utf8(res.stderr).unwrap_or_else(|e| format!(
"Could not parse stderr: {}",

View File

@@ -1,9 +1,9 @@
use std::process::Stdio;
use std::time::{Duration, UNIX_EPOCH};
use anyhow::anyhow;
use chrono::{DateTime, Utc};
use clap::ArgMatches;
use color_eyre::eyre::eyre;
use futures::TryStreamExt;
use rpc_toolkit::command;
use serde::{Deserialize, Serialize};
@@ -123,10 +123,12 @@ pub async fn fetch_logs(
.args(args)
.stdout(Stdio::piped())
.spawn()?;
let out =
BufReader::new(child.stdout.take().ok_or_else(|| {
Error::new(anyhow!("No stdout available"), crate::ErrorKind::Journald)
})?);
let out = BufReader::new(
child
.stdout
.take()
.ok_or_else(|| Error::new(eyre!("No stdout available"), crate::ErrorKind::Journald))?,
);
let journalctl_entries = LinesStream::new(out.lines());

View File

@@ -4,8 +4,8 @@ use std::sync::atomic::AtomicUsize;
use std::sync::Arc;
use std::task::Poll;
use anyhow::anyhow;
use bollard::container::StopContainerOptions;
use color_eyre::eyre::eyre;
use patch_db::DbHandle;
use sqlx::{Executor, Sqlite};
use tokio::sync::watch::error::RecvError;
@@ -100,7 +100,7 @@ impl ManagerMap {
res.into_iter().fold(Ok(()), |res, x| match (res, x) {
(Ok(()), x) => x,
(Err(e), Ok(())) => Err(e),
(Err(e1), Err(e2)) => Err(Error::new(anyhow!("{}, {}", e1.source, e2.source), e1.kind)),
(Err(e1), Err(e2)) => Err(Error::new(eyre!("{}, {}", e1.source, e2.source), e1.kind)),
})
}
@@ -182,10 +182,7 @@ async fn run_main(state: &Arc<ManagerSharedState>) -> Result<Result<(), (i32, St
Poll::Ready(res) => {
return res
.map_err(|_| {
Error::new(
anyhow!("Manager runtime panicked!"),
crate::ErrorKind::Docker,
)
Error::new(eyre!("Manager runtime panicked!"), crate::ErrorKind::Docker)
})
.and_then(|a| a)
}
@@ -213,7 +210,7 @@ async fn run_main(state: &Arc<ManagerSharedState>) -> Result<Result<(), (i32, St
.get(id)
.ok_or_else(|| {
Error::new(
anyhow!("interface {} missing key", id),
eyre!("interface {} missing key", id),
crate::ErrorKind::Tor,
)
})?
@@ -225,12 +222,7 @@ async fn run_main(state: &Arc<ManagerSharedState>) -> Result<Result<(), (i32, St
.await?;
let res = runtime
.await
.map_err(|_| {
Error::new(
anyhow!("Manager runtime panicked!"),
crate::ErrorKind::Docker,
)
})
.map_err(|_| Error::new(eyre!("Manager runtime panicked!"), crate::ErrorKind::Docker))
.and_then(|a| a);
state
.ctx
@@ -350,7 +342,7 @@ impl Manager {
pub async fn stop(&self) -> Result<(), Error> {
self.shared.on_stop.send(OnStop::Sleep).map_err(|_| {
Error::new(
anyhow!("Manager has already been shutdown"),
eyre!("Manager has already been shutdown"),
crate::ErrorKind::Docker,
)
})?;
@@ -382,7 +374,7 @@ impl Manager {
pub async fn start(&self) -> Result<(), Error> {
self.shared.on_stop.send(OnStop::Restart).map_err(|_| {
Error::new(
anyhow!("Manager has already been shutdown"),
eyre!("Manager has already been shutdown"),
crate::ErrorKind::Docker,
)
})?;
@@ -442,7 +434,7 @@ impl Manager {
if let Some(thread) = self.thread.take().await {
thread.await.map_err(|e| {
Error::new(
anyhow!("Manager thread panicked: {}", e),
eyre!("Manager thread panicked: {}", e),
crate::ErrorKind::Docker,
)
})?;

View File

@@ -1,5 +1,5 @@
use anyhow::anyhow;
use basic_cookies::Cookie;
use color_eyre::eyre::eyre;
use digest::Digest;
use futures::future::BoxFuture;
use futures::{FutureExt, TryFutureExt};
@@ -29,7 +29,7 @@ pub fn get_id(req: &RequestParts) -> Result<String, Error> {
}
}
Err(Error::new(
anyhow!("UNAUTHORIZED"),
eyre!("UNAUTHORIZED"),
crate::ErrorKind::Authorization,
))
}
@@ -50,7 +50,7 @@ pub async fn is_authed(ctx: &RpcContext, id: &str) -> Result<(), Error> {
.await?;
if session.rows_affected() == 0 {
return Err(Error::new(
anyhow!("UNAUTHORIZED"),
eyre!("UNAUTHORIZED"),
crate::ErrorKind::Authorization,
));
}

View File

@@ -19,7 +19,7 @@ pub async fn diagnostic<M: Metadata>(
if let Err(e) = rpc_res {
if e.code == -32601 {
*e = Error::new(
anyhow::anyhow!(
color_eyre::eyre::eyre!(
"{} is not available on the Diagnostic API",
method
),

View File

@@ -3,7 +3,7 @@ use std::sync::Arc;
use aes::cipher::{CipherKey, NewCipher, Nonce, StreamCipher};
use aes::Aes256Ctr;
use anyhow::anyhow;
use color_eyre::eyre::eyre;
use futures::future::BoxFuture;
use futures::{FutureExt, Stream};
use hmac::Hmac;
@@ -193,7 +193,7 @@ pub fn encrypt<
&req.headers,
res_parts,
Err(Error::new(
anyhow!("Must be encrypted"),
eyre!("Must be encrypted"),
crate::ErrorKind::Authorization,
)
.into()),

View File

@@ -1,4 +1,4 @@
use anyhow::anyhow;
use color_eyre::eyre::eyre;
use emver::VersionRange;
use indexmap::IndexMap;
use patch_db::HasModel;
@@ -45,7 +45,7 @@ impl Migrations {
)
.await?
.map_err(|e| {
Error::new(anyhow!("{}", e.1), crate::ErrorKind::MigrationFailed)
Error::new(eyre!("{}", e.1), crate::ErrorKind::MigrationFailed)
})?,
)
} else {
@@ -78,7 +78,7 @@ impl Migrations {
)
.await?
.map_err(|e| {
Error::new(anyhow!("{}", e.1), crate::ErrorKind::MigrationFailed)
Error::new(eyre!("{}", e.1), crate::ErrorKind::MigrationFailed)
})?,
)
} else {

View File

@@ -1,7 +1,7 @@
use std::collections::BTreeMap;
use std::path::Path;
use anyhow::anyhow;
use color_eyre::eyre::eyre;
use futures::TryStreamExt;
use indexmap::IndexSet;
use itertools::Either;
@@ -86,10 +86,7 @@ impl Interfaces {
Ok(if let Either::Right(r) = qr {
let mut buf = [0; 64];
buf.clone_from_slice(r.key.get(0..64).ok_or_else(|| {
Error::new(
anyhow!("Invalid Tor Key Length"),
crate::ErrorKind::Database,
)
Error::new(eyre!("Invalid Tor Key Length"), crate::ErrorKind::Database)
})?);
Some((InterfaceId::from(Id::try_from(r.interface)?), buf.into()))
} else {

View File

@@ -1,6 +1,6 @@
use std::cmp::Ordering;
use anyhow::anyhow;
use color_eyre::eyre::eyre;
use openssl::asn1::{Asn1Integer, Asn1Time};
use openssl::bn::{BigNum, MsbOption};
use openssl::ec::{EcGroup, EcKey};
@@ -115,7 +115,7 @@ impl SslStore {
let n = sqlx::query!("UPDATE certificates SET priv_key_pem = ?, certificate_pem = ?, updated_at = datetime('now') WHERE lookup_string = ?", key_str, cert_str, lookup_string).execute(&self.secret_store).await?;
if n.rows_affected() == 0 {
return Err(Error::new(
anyhow!(
eyre!(
"Attempted to update non-existent certificate: {}",
lookup_string
),

View File

@@ -2,8 +2,8 @@ use std::collections::BTreeMap;
use std::net::{Ipv4Addr, SocketAddr};
use std::time::Duration;
use anyhow::anyhow;
use clap::ArgMatches;
use color_eyre::eyre::eyre;
use futures::future::BoxFuture;
use futures::FutureExt;
use reqwest::Client;
@@ -66,12 +66,11 @@ where
.tor_key;
let mut buf = [0; 64];
buf.clone_from_slice(key.get(0..64).ok_or_else(|| {
Error::new(
anyhow!("Invalid Tor Key Length"),
crate::ErrorKind::Database,
)
})?);
buf.clone_from_slice(
key.get(0..64).ok_or_else(|| {
Error::new(eyre!("Invalid Tor Key Length"), crate::ErrorKind::Database)
})?,
);
Ok(buf.into())
}
@@ -158,10 +157,7 @@ impl TorControllerInner {
self.connection
.as_mut()
.ok_or_else(|| {
Error::new(
anyhow!("Missing Tor Control Connection"),
ErrorKind::Unknown,
)
Error::new(eyre!("Missing Tor Control Connection"), ErrorKind::Unknown)
})?
.add_onion_v3(
&key,
@@ -194,7 +190,7 @@ impl TorControllerInner {
self.connection
.as_mut()
.ok_or_else(|| {
Error::new(anyhow!("Missing Tor Control Connection"), ErrorKind::Tor)
Error::new(eyre!("Missing Tor Control Connection"), ErrorKind::Tor)
})?
.del_onion(
&key.public()
@@ -219,7 +215,7 @@ impl TorControllerInner {
.load_protocol_info()
.await?
.make_auth_data()?
.ok_or_else(|| anyhow!("Cookie Auth Not Available"))
.ok_or_else(|| eyre!("Cookie Auth Not Available"))
.with_kind(crate::ErrorKind::Tor)?;
conn.authenticate(&auth).await?;
let mut connection: AuthenticatedConnection = conn.into_authenticated().await;
@@ -243,7 +239,7 @@ impl TorControllerInner {
);
self.connection
.as_mut()
.ok_or_else(|| Error::new(anyhow!("Missing Tor Control Connection"), ErrorKind::Tor))?
.ok_or_else(|| Error::new(eyre!("Missing Tor Control Connection"), ErrorKind::Tor))?
.add_onion_v3(
&self.embassyd_tor_key,
false,
@@ -290,7 +286,7 @@ impl TorControllerInner {
.load_protocol_info()
.await?
.make_auth_data()?
.ok_or_else(|| anyhow!("Cookie Auth Not Available"))
.ok_or_else(|| eyre!("Cookie Auth Not Available"))
.with_kind(crate::ErrorKind::Tor)?;
new_conn.authenticate(&auth).await?;
new_connection = new_conn.into_authenticated().await;
@@ -339,7 +335,7 @@ impl TorControllerInner {
async fn list_services(&mut self) -> Result<Vec<OnionAddressV3>, Error> {
self.connection
.as_mut()
.ok_or_else(|| Error::new(anyhow!("Missing Tor Control Connection"), ErrorKind::Tor))?
.ok_or_else(|| Error::new(eyre!("Missing Tor Control Connection"), ErrorKind::Tor))?
.get_info("onions/current")
.await?
.lines()
@@ -405,7 +401,7 @@ async fn test() {
.unwrap()
.make_auth_data()
.unwrap()
.ok_or_else(|| anyhow!("Cookie Auth Not Available"))
.ok_or_else(|| eyre!("Cookie Auth Not Available"))
.with_kind(crate::ErrorKind::Tor)
.unwrap();
conn.authenticate(&auth).await.unwrap();

View File

@@ -25,13 +25,13 @@ pub async fn add(
let wpa_supplicant = WpaCli { interface: "wlan0" }; // TODO: pull from config
if !ssid.is_ascii() {
return Err(Error::new(
anyhow::anyhow!("SSID may not have special characters"),
color_eyre::eyre::eyre!("SSID may not have special characters"),
ErrorKind::Wifi,
));
}
if !password.is_ascii() {
return Err(Error::new(
anyhow::anyhow!("WiFi Password may not have special characters"),
color_eyre::eyre::eyre!("WiFi Password may not have special characters"),
ErrorKind::Wifi,
));
}
@@ -75,7 +75,7 @@ pub async fn add(
pub async fn connect(#[arg] ssid: String) -> Result<(), Error> {
if !ssid.is_ascii() {
return Err(Error::new(
anyhow::anyhow!("SSID may not have special characters"),
color_eyre::eyre::eyre!("SSID may not have special characters"),
ErrorKind::Wifi,
));
}
@@ -113,7 +113,7 @@ pub async fn connect(#[arg] ssid: String) -> Result<(), Error> {
pub async fn delete(#[arg] ssid: String) -> Result<(), Error> {
if !ssid.is_ascii() {
return Err(Error::new(
anyhow::anyhow!("SSID may not have special characters"),
color_eyre::eyre::eyre!("SSID may not have special characters"),
ErrorKind::Wifi,
));
}
@@ -128,7 +128,7 @@ pub async fn delete(#[arg] ssid: String) -> Result<(), Error> {
if interface_connected("eth0").await? {
wpa_supplicant.remove_network(&ssid).await?;
} else {
return Err(Error::new(anyhow::anyhow!("Forbidden: Deleting this Network would make your Embassy Unreachable. Either connect to ethernet or connect to a different WiFi network to remedy this."), ErrorKind::Wifi));
return Err(Error::new(color_eyre::eyre::eyre!("Forbidden: Deleting this Network would make your Embassy Unreachable. Either connect to ethernet or connect to a different WiFi network to remedy this."), ErrorKind::Wifi));
}
}
}
@@ -401,7 +401,7 @@ impl<'a> WpaCli<'a> {
.await?;
let e = || {
Error::new(
anyhow::anyhow!("Invalid output from wpa_cli signal_poll"),
color_eyre::eyre::eyre!("Invalid output from wpa_cli signal_poll"),
ErrorKind::Wifi,
)
};
@@ -423,7 +423,7 @@ impl<'a> WpaCli<'a> {
let m_id = self.check_network(ssid).await?;
match m_id {
None => Err(Error::new(
anyhow::anyhow!("SSID Not Found"),
color_eyre::eyre::eyre!("SSID Not Found"),
ErrorKind::Wifi,
)),
Some(x) => {
@@ -513,7 +513,7 @@ pub async fn interface_connected(interface: &str) -> Result<bool, Error> {
pub fn country_code_parse(code: &str, _matches: &ArgMatches<'_>) -> Result<CountryCode, Error> {
CountryCode::for_alpha2(code).or(Err(Error::new(
anyhow::anyhow!("Invalid Country Code: {}", code),
color_eyre::eyre::eyre!("Invalid Country Code: {}", code),
ErrorKind::Wifi,
)))
}

View File

@@ -2,8 +2,8 @@ use std::collections::{BTreeMap, HashMap};
use std::fmt;
use std::str::FromStr;
use anyhow::anyhow;
use chrono::{DateTime, Utc};
use color_eyre::eyre::eyre;
use patch_db::PatchDb;
use rpc_toolkit::command;
use sqlx::SqlitePool;
@@ -58,7 +58,7 @@ pub async fn list(
Ok(a) => a,
Err(e) => {
return Err(Error::new(
anyhow!("Invalid Notification Data: {}", e),
eyre!("Invalid Notification Data: {}", e),
ErrorKind::ParseDbField,
))
}
@@ -100,7 +100,7 @@ pub async fn list(
Ok(a) => a,
Err(e) => {
return Err(Error::new(
anyhow!("Invalid Notification Data: {}", e),
eyre!("Invalid Notification Data: {}", e),
ErrorKind::ParseDbField,
))
}
@@ -168,7 +168,7 @@ pub struct InvalidNotificationLevel(String);
impl From<InvalidNotificationLevel> for crate::Error {
fn from(val: InvalidNotificationLevel) -> Self {
Error::new(
anyhow!("Invalid Notification Level: {}", val.0),
eyre!("Invalid Notification Level: {}", val.0),
ErrorKind::ParseDbField,
)
}

View File

@@ -1,5 +1,5 @@
use anyhow::anyhow;
use clap::ArgMatches;
use color_eyre::eyre::eyre;
use rpc_toolkit::command;
use serde_json::Value;
@@ -26,7 +26,7 @@ pub async fn fetch_properties(ctx: RpcContext, id: PackageId) -> Result<Value, E
.get(&mut db, true)
.await?
.to_owned()
.ok_or_else(|| Error::new(anyhow!("{} is not installed", id), ErrorKind::NotFound))?;
.ok_or_else(|| Error::new(eyre!("{} is not installed", id), ErrorKind::NotFound))?;
if let Some(props) = manifest.properties {
props
.execute::<(), Value>(
@@ -39,7 +39,7 @@ pub async fn fetch_properties(ctx: RpcContext, id: PackageId) -> Result<Value, E
false,
)
.await?
.map_err(|_| Error::new(anyhow!("Properties failure!"), ErrorKind::Docker))
.map_err(|_| Error::new(eyre!("Properties failure!"), ErrorKind::Docker))
.and_then(|a| Ok(a))
} else {
Ok(Value::Null)

View File

@@ -1,7 +1,7 @@
use std::collections::BTreeMap;
use std::io::Write;
use anyhow::anyhow;
use color_eyre::eyre::eyre;
use ed25519_dalek::{PublicKey, Signature};
use tokio::io::{AsyncRead, AsyncReadExt};
@@ -38,7 +38,7 @@ impl Header {
reader.read_exact(&mut magic).await?;
if magic != MAGIC {
return Err(Error::new(
anyhow!("Incorrect Magic"),
eyre!("Incorrect Magic"),
crate::ErrorKind::ParseS9pk,
));
}
@@ -46,7 +46,7 @@ impl Header {
reader.read_exact(&mut version).await?;
if version[0] != VERSION {
return Err(Error::new(
anyhow!("Unknown Version"),
eyre!("Unknown Version"),
crate::ErrorKind::ParseS9pk,
));
}

View File

@@ -1,6 +1,6 @@
use std::path::PathBuf;
use anyhow::anyhow;
use color_eyre::eyre::eyre;
use rpc_toolkit::command;
use crate::context::SdkContext;
@@ -40,7 +40,7 @@ pub fn pack(#[context] ctx: SdkContext, #[arg] path: Option<PathBuf>) -> Result<
.with_kind(crate::ErrorKind::Deserialization)?
} else {
return Err(Error::new(
anyhow!("manifest not found"),
eyre!("manifest not found"),
crate::ErrorKind::Pack,
));
};

View File

@@ -3,7 +3,7 @@ use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicU64, Ordering};
use std::time::Duration;
use anyhow::anyhow;
use color_eyre::eyre::eyre;
use futures::future::BoxFuture;
use futures::{FutureExt, TryStreamExt};
use rpc_toolkit::command;
@@ -123,7 +123,7 @@ pub async fn execute_inner(
) -> Result<String, Error> {
if ctx.recovery_status.read().await.is_some() {
return Err(Error::new(
anyhow!("Cannot execute setup while in recovery!"),
eyre!("Cannot execute setup while in recovery!"),
crate::ErrorKind::InvalidRequest,
));
}
@@ -173,7 +173,7 @@ pub async fn execute_inner(
.map(|v| &*v.version < &emver::Version::new(0, 2, 8, 0))
.unwrap_or(true)
{
return Err(Error::new(anyhow!("Unsupported version of EmbassyOS. Please update to at least 0.2.8 before recovering."), crate::ErrorKind::VersionIncompatible));
return Err(Error::new(eyre!("Unsupported version of EmbassyOS. Please update to at least 0.2.8 before recovering."), crate::ErrorKind::VersionIncompatible));
}
tokio::spawn(async move {
if let Err(e) = recover(ctx.clone(), guid, recovery_drive, recovery_password).await {
@@ -206,7 +206,7 @@ async fn recover(
recover_v3(&ctx, recovery_drive, recovery_password).await?;
} else {
return Err(Error::new(
anyhow!("Unsupported version of EmbassyOS: {}", recovery_version),
eyre!("Unsupported version of EmbassyOS: {}", recovery_version),
crate::ErrorKind::VersionIncompatible,
));
}
@@ -313,7 +313,7 @@ async fn recover_v2(ctx: &SetupContext, recovery_drive: DiskInfo) -> Result<(),
.get(1)
.ok_or_else(|| {
Error::new(
anyhow!("missing rootfs partition"),
eyre!("missing rootfs partition"),
crate::ErrorKind::Filesystem,
)
})?

View File

@@ -36,7 +36,7 @@ impl SoundInterface {
.await
.map_err(|e| {
Error::new(
anyhow::anyhow!("Sound file lock panicked: {}", e),
color_eyre::eyre::eyre!("Sound file lock panicked: {}", e),
ErrorKind::SoundError,
)
})?

View File

@@ -1,8 +1,8 @@
use std::path::Path;
use anyhow::anyhow;
use chrono::Utc;
use clap::ArgMatches;
use color_eyre::eyre::eyre;
use rpc_toolkit::command;
use sqlx::{Pool, Sqlite};
@@ -84,10 +84,7 @@ pub async fn add(#[context] ctx: RpcContext, #[arg] key: PubKey) -> Result<SshKe
created_at,
})
}
Some(_) => Err(Error::new(
anyhow!("Duplicate ssh key"),
ErrorKind::Duplicate,
)),
Some(_) => Err(Error::new(eyre!("Duplicate ssh key"), ErrorKind::Duplicate)),
}
}
#[command(display(display_none))]
@@ -102,7 +99,7 @@ pub async fn delete(#[context] ctx: RpcContext, #[arg] fingerprint: String) -> R
// if not in DB, Err404
if n == 0 {
Err(Error {
source: anyhow::anyhow!("SSH Key Not Found"),
source: color_eyre::eyre::eyre!("SSH Key Not Found"),
kind: crate::error::ErrorKind::NotFound,
revision: None,
})
@@ -180,7 +177,7 @@ pub async fn sync_keys_from_db<P: AsRef<Path>>(pool: &Pool<Sqlite>, dest: P) ->
.collect();
let ssh_dir = dest.parent().ok_or_else(|| {
Error::new(
anyhow!("SSH Key File cannot be \"/\""),
eyre!("SSH Key File cannot be \"/\""),
crate::ErrorKind::Filesystem,
)
})?;

View File

@@ -1,8 +1,8 @@
use std::collections::{BTreeMap, BTreeSet};
use std::sync::Arc;
use anyhow::anyhow;
use chrono::{DateTime, Utc};
use color_eyre::eyre::eyre;
use futures::{FutureExt, StreamExt};
use patch_db::{DbHandle, HasModel, Map, ModelData};
use serde::{Deserialize, Serialize};
@@ -60,7 +60,7 @@ pub async fn synchronize_all(ctx: &RpcContext) -> Result<(), Error> {
))
.await
.ok_or_else(|| {
Error::new(anyhow!("No Manager"), crate::ErrorKind::Docker)
Error::new(eyre!("No Manager"), crate::ErrorKind::Docker)
})?,
)
} else {

View File

@@ -209,7 +209,7 @@ pub async fn metrics(
) -> Result<Metrics, Error> {
match ctx.metrics_cache.read().await.clone() {
None => Err(Error {
source: anyhow::anyhow!("No Metrics Found"),
source: color_eyre::eyre::eyre!("No Metrics Found"),
kind: ErrorKind::NotFound,
revision: None,
}),
@@ -456,7 +456,7 @@ async fn get_proc_stat() -> Result<ProcStat, Error> {
.map(|s| {
s.parse::<u64>().map_err(|e| {
Error::new(
anyhow::anyhow!("Invalid /proc/stat column value: {}", e),
color_eyre::eyre::eyre!("Invalid /proc/stat column value: {}", e),
ErrorKind::ParseSysInfo,
)
})
@@ -465,7 +465,7 @@ async fn get_proc_stat() -> Result<ProcStat, Error> {
if stats.len() < 10 {
Err(Error {
source: anyhow::anyhow!(
source: color_eyre::eyre::eyre!(
"Columns missing from /proc/stat. Need 10, found {}",
stats.len()
),
@@ -525,7 +525,7 @@ async fn get_mem_info() -> Result<MetricsMemory, Error> {
};
fn get_num_kb(l: &str) -> Result<u64, Error> {
let e = Error::new(
anyhow::anyhow!("Invalid meminfo line: {}", l),
color_eyre::eyre::eyre!("Invalid meminfo line: {}", l),
ErrorKind::ParseSysInfo,
);
match l.split_whitespace().skip(1).next() {
@@ -553,7 +553,7 @@ async fn get_mem_info() -> Result<MetricsMemory, Error> {
}
fn ensure_present(a: Option<u64>, field: &str) -> Result<u64, Error> {
a.ok_or(Error::new(
anyhow::anyhow!("{} missing from /proc/meminfo", field),
color_eyre::eyre::eyre!("{} missing from /proc/meminfo", field),
ErrorKind::ParseSysInfo,
))
}
@@ -617,7 +617,7 @@ async fn get_disk_info() -> Result<MetricsDisk, Error> {
.parse::<f64>()
.map_err(|e| {
Error::new(
anyhow::anyhow!("Could not parse disk size: {}", e),
color_eyre::eyre::eyre!("Could not parse disk size: {}", e),
ErrorKind::ParseSysInfo,
)
})?;
@@ -626,7 +626,7 @@ async fn get_disk_info() -> Result<MetricsDisk, Error> {
.parse::<f64>()
.map_err(|e| {
Error::new(
anyhow::anyhow!("Could not parse disk alloc: {}", e),
color_eyre::eyre::eyre!("Could not parse disk alloc: {}", e),
ErrorKind::ParseSysInfo,
)
})?;
@@ -635,7 +635,7 @@ async fn get_disk_info() -> Result<MetricsDisk, Error> {
.parse::<f64>()
.map_err(|e| {
Error::new(
anyhow::anyhow!("Could not parse disk alloc: {}", e),
color_eyre::eyre::eyre!("Could not parse disk alloc: {}", e),
ErrorKind::ParseSysInfo,
)
})?;

View File

@@ -3,8 +3,8 @@ use std::path::{Path, PathBuf};
use std::sync::Arc;
use std::time::Duration;
use anyhow::{anyhow, Result};
use clap::ArgMatches;
use color_eyre::eyre::{eyre, Result};
use digest::Digest;
use emver::Version;
use futures::Stream;
@@ -183,7 +183,7 @@ async fn maybe_do_update(ctx: RpcContext) -> Result<Option<Arc<Revision>>, Error
match &info.status {
ServerStatus::Updating => {
return Err(Error::new(
anyhow!("Server is already updating!"),
eyre!("Server is already updating!"),
crate::ErrorKind::InvalidRequest,
))
}
@@ -192,7 +192,7 @@ async fn maybe_do_update(ctx: RpcContext) -> Result<Option<Arc<Revision>>, Error
}
ServerStatus::BackingUp => {
return Err(Error::new(
anyhow!("Server is backing up!"),
eyre!("Server is backing up!"),
crate::ErrorKind::InvalidRequest,
))
}
@@ -272,7 +272,7 @@ async fn query_mounted_label() -> Result<(NewLabel, CurrentLabel), Error> {
match &PARSE_COLOR.captures(&output).ok_or_else(|| {
Error::new(
anyhow!("Can't find pattern in {}", output),
eyre!("Can't find pattern in {}", output),
crate::ErrorKind::Filesystem,
)
})?[1]
@@ -287,7 +287,7 @@ async fn query_mounted_label() -> Result<(NewLabel, CurrentLabel), Error> {
)),
e => {
return Err(Error::new(
anyhow!("Could not find a mounted resource for {}", e),
eyre!("Could not find a mounted resource for {}", e),
crate::ErrorKind::Filesystem,
))
}
@@ -322,7 +322,7 @@ async fn download_file<'a, Db: DbHandle + 'a>(
let hash_from_header: String = "".to_owned(); // download_request
// .headers()
// .get(HEADER_KEY)
// .ok_or_else(|| Error::new(anyhow!("No {} in headers", HEADER_KEY), ErrorKind::Network))?
// .ok_or_else(|| Error::new(eyre!("No {} in headers", HEADER_KEY), ErrorKind::Network))?
// .to_str()
// .with_kind(ErrorKind::InvalidRequest)?
// .to_owned();
@@ -373,7 +373,7 @@ async fn write_stream_to_label<Db: DbHandle>(
async fn check_download(hash_from_header: &str, file_digest: Vec<u8>) -> Result<(), Error> {
// if hex::decode(hash_from_header).with_kind(ErrorKind::Network)? != file_digest {
// return Err(Error::new(
// anyhow!("Hash sum does not match source"),
// eyre!("Hash sum does not match source"),
// ErrorKind::Network,
// ));
// }

View File

@@ -100,7 +100,7 @@ where
let mut buffer = Vec::new();
reader.read_to_end(&mut buffer).await?;
serde_yaml::from_slice(&buffer)
.map_err(anyhow::Error::from)
.map_err(color_eyre::eyre::Error::from)
.with_kind(crate::ErrorKind::Deserialization)
}
@@ -123,7 +123,7 @@ where
let mut buffer = Vec::new();
reader.read_to_end(&mut buffer).await?;
serde_toml::from_slice(&buffer)
.map_err(anyhow::Error::from)
.map_err(color_eyre::eyre::Error::from)
.with_kind(crate::ErrorKind::Deserialization)
}
@@ -146,7 +146,7 @@ where
let mut buffer = Vec::new();
reader.read_to_end(&mut buffer).await?;
serde_cbor::de::from_reader(buffer.as_slice())
.map_err(anyhow::Error::from)
.map_err(color_eyre::eyre::Error::from)
.with_kind(crate::ErrorKind::Deserialization)
}
@@ -158,7 +158,7 @@ where
let mut buffer = Vec::new();
reader.read_to_end(&mut buffer).await?;
serde_json::from_slice(&buffer)
.map_err(anyhow::Error::from)
.map_err(color_eyre::eyre::Error::from)
.with_kind(crate::ErrorKind::Deserialization)
}

View File

@@ -7,9 +7,9 @@ use std::process::{exit, Stdio};
use std::str::FromStr;
use std::time::Duration;
use anyhow::anyhow;
use async_trait::async_trait;
use clap::ArgMatches;
use color_eyre::eyre::{self, eyre};
use digest::Digest;
use patch_db::{HasModel, Model};
use serde::{Deserialize, Deserializer, Serialize, Serializer};
@@ -166,14 +166,14 @@ pub async fn daemon<F: FnMut() -> Fut, Fut: Future<Output = ()> + Send + 'static
mut f: F,
cooldown: std::time::Duration,
mut shutdown: tokio::sync::broadcast::Receiver<Option<Shutdown>>,
) -> Result<(), anyhow::Error> {
) -> Result<(), eyre::Error> {
loop {
tokio::select! {
_ = shutdown.recv() => return Ok(()),
_ = tokio::time::sleep(cooldown) => (),
}
match tokio::spawn(f()).await {
Err(e) if e.is_panic() => return Err(anyhow!("daemon panicked!")),
Err(e) if e.is_panic() => return Err(eyre!("daemon panicked!")),
_ => (),
}
}
@@ -647,7 +647,7 @@ pub fn parse_stdin_deserializable<T: for<'de> Deserialize<'de>>(
pub fn parse_duration(arg: &str, _: &ArgMatches<'_>) -> Result<Duration, Error> {
let units_idx = arg.find(|c: char| c.is_alphabetic()).ok_or_else(|| {
Error::new(
anyhow!("Must specify units for duration"),
eyre!("Must specify units for duration"),
crate::ErrorKind::Deserialization,
)
})?;
@@ -665,7 +665,7 @@ pub fn parse_duration(arg: &str, _: &ArgMatches<'_>) -> Result<Duration, Error>
"us" => Ok(Duration::from_micros(num.parse()?)),
"ns" => Ok(Duration::from_nanos(num.parse()?)),
_ => Err(Error::new(
anyhow!("Invalid units for duration"),
eyre!("Invalid units for duration"),
crate::ErrorKind::Deserialization,
)),
}