diff --git a/appmgr/Cargo.lock b/appmgr/Cargo.lock index 3c39239d6..5141cadc1 100644 --- a/appmgr/Cargo.lock +++ b/appmgr/Cargo.lock @@ -2,6 +2,21 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "addr2line" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e61f2b7f93d2c7d2b08263acaa4a363b3e276806c68af6134c44f523bf1aacd" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + [[package]] name = "aes" version = "0.7.5" @@ -44,6 +59,15 @@ dependencies = [ "winapi", ] +[[package]] +name = "ansi_term" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" +dependencies = [ + "winapi", +] + [[package]] name = "anyhow" version = "1.0.44" @@ -117,6 +141,21 @@ dependencies = [ "libc", ] +[[package]] +name = "backtrace" +version = "0.3.61" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7a905d892734eea339e896738c14b9afce22b5318f64b951e70bf3844419b01" +dependencies = [ + "addr2line", + "cc", + "cfg-if 1.0.0", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + [[package]] name = "base-x" version = "0.2.8" @@ -390,7 +429,7 @@ version = "2.33.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002" dependencies = [ - "ansi_term", + "ansi_term 0.11.0", "atty", "bitflags", "strsim 0.8.0", @@ -399,6 +438,33 @@ dependencies = [ "vec_map", ] +[[package]] +name = "color-eyre" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f1885697ee8a177096d42f158922251a41973117f6d8a234cee94b9509157b7" +dependencies = [ + "backtrace", + "color-spantrace", + "eyre", + "indenter", + "once_cell", + "owo-colors", + "tracing-error", +] + +[[package]] +name = "color-spantrace" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6eee477a4a8a72f4addd4de416eb56d54bc307b284d6601bafdee1f4ea462d1" +dependencies = [ + "once_cell", + "owo-colors", + "tracing-core", + "tracing-error", +] + [[package]] name = "const_fn" version = "0.4.8" @@ -759,7 +825,6 @@ name = "embassy-os" version = "0.3.0-pre.0" dependencies = [ "aes", - "anyhow", "async-trait", "avahi-sys", "base32", @@ -768,6 +833,7 @@ dependencies = [ "chrono", "ciborium", "clap", + "color-eyre", "cookie_store 0.15.0", "digest", "divrem", @@ -824,6 +890,9 @@ dependencies = [ "tokio-util", "toml", "torut", + "tracing", + "tracing-futures", + "tracing-subscriber", "typed-builder", "url", ] @@ -890,6 +959,16 @@ dependencies = [ "termcolor", ] +[[package]] +name = "eyre" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "221239d1d5ea86bf5d6f91c9d6bc3646ffe471b08ff9b0f91c44f115ac969d2b" +dependencies = [ + "indenter", + "once_cell", +] + [[package]] name = "fd-lock-rs" version = "0.1.3" @@ -1100,6 +1179,12 @@ dependencies = [ "wasi 0.10.0+wasi-snapshot-preview1", ] +[[package]] +name = "gimli" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0a01e0497841a3b2db4f8afa483cce65f7e96a3498bd6c541734792aeac8fe7" + [[package]] name = "git-version" version = "0.3.5" @@ -1337,6 +1422,12 @@ dependencies = [ "unicode-normalization", ] +[[package]] +name = "indenter" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" + [[package]] name = "indexmap" version = "1.7.0" @@ -1559,6 +1650,15 @@ dependencies = [ "cfg-if 1.0.0", ] +[[package]] +name = "matchers" +version = "0.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f099785f7595cc4b4553a174ce30dd7589ef93391ff414dbb67f62392b9e0ce1" +dependencies = [ + "regex-automata", +] + [[package]] name = "matches" version = "0.1.9" @@ -1603,6 +1703,16 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c835948974f68e0bd58636fc6c5b1fbff7b297e3046f11b3b3c18bbac012c6d" +[[package]] +name = "miniz_oxide" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a92518e98c078586bc6c934028adcca4c92a53d6a958196de835170a01d84e4b" +dependencies = [ + "adler", + "autocfg", +] + [[package]] name = "mio" version = "0.7.13" @@ -1803,6 +1913,15 @@ dependencies = [ "libc", ] +[[package]] +name = "object" +version = "0.26.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39f37e50073ccad23b6d09bcb5b263f4e76d3bb6038e4a3c08e52162ffa8abc2" +dependencies = [ + "memchr", +] + [[package]] name = "once_cell" version = "1.8.0" @@ -1871,6 +1990,12 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "owo-colors" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2386b4ebe91c2f7f51082d4cefa145d030e33a1842a96b12e4885cc3c01f7a55" + [[package]] name = "parking_lot" version = "0.11.2" @@ -2341,6 +2466,9 @@ name = "regex-automata" version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" +dependencies = [ + "regex-syntax", +] [[package]] name = "regex-syntax" @@ -2483,6 +2611,12 @@ dependencies = [ "crossbeam-utils", ] +[[package]] +name = "rustc-demangle" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342" + [[package]] name = "rustc-hash" version = "1.1.0" @@ -2783,6 +2917,15 @@ dependencies = [ "opaque-debug", ] +[[package]] +name = "sharded-slab" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "740223c51853f3145fe7c90360d2d4232f2b62e3449489c207eccde818979982" +dependencies = [ + "lazy_static", +] + [[package]] name = "shlex" version = "0.1.1" @@ -3471,9 +3614,21 @@ checksum = "84f96e095c0c82419687c20ddf5cb3eadb61f4e1405923c9dc8e53a1adacbda8" dependencies = [ "cfg-if 1.0.0", "pin-project-lite 0.2.7", + "tracing-attributes", "tracing-core", ] +[[package]] +name = "tracing-attributes" +version = "0.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4f480b8f81512e825f337ad51e94c1eb5d3bbdf2b363dcd01e2b19a9ffe3f8e" +dependencies = [ + "proc-macro2 1.0.29", + "quote 1.0.9", + "syn 1.0.77", +] + [[package]] name = "tracing-core" version = "0.1.20" @@ -3483,6 +3638,69 @@ dependencies = [ "lazy_static", ] +[[package]] +name = "tracing-error" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4d7c0b83d4a500748fa5879461652b361edf5c9d51ede2a2ac03875ca185e24" +dependencies = [ + "tracing", + "tracing-subscriber", +] + +[[package]] +name = "tracing-futures" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2" +dependencies = [ + "pin-project", + "tracing", +] + +[[package]] +name = "tracing-log" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6923477a48e41c1951f1999ef8bb5a3023eb723ceadafe78ffb65dc366761e3" +dependencies = [ + "lazy_static", + "log", + "tracing-core", +] + +[[package]] +name = "tracing-serde" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb65ea441fbb84f9f6748fd496cf7f63ec9af5bca94dd86456978d055e8eb28b" +dependencies = [ + "serde", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.2.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e0d2eaa99c3c2e41547cfa109e910a68ea03823cccad4a0525dcbc9b01e8c71" +dependencies = [ + "ansi_term 0.12.1", + "chrono", + "lazy_static", + "matchers", + "regex", + "serde", + "serde_json", + "sharded-slab", + "smallvec", + "thread_local", + "tracing", + "tracing-core", + "tracing-log", + "tracing-serde", +] + [[package]] name = "treediff" version = "4.0.0" diff --git a/appmgr/Cargo.toml b/appmgr/Cargo.toml index dc3f1ef10..8997a57ae 100644 --- a/appmgr/Cargo.toml +++ b/appmgr/Cargo.toml @@ -44,7 +44,6 @@ sound = [] [dependencies] aes = { version = "0.7.5", features = ["ctr"] } -anyhow = "1.0.44" async-trait = "0.1.51" avahi-sys = { git = "https://github.com/Start9Labs/avahi-sys", version = "0.10.0", branch = "feature/dynamic-linking", features = [ "dynamic", @@ -54,6 +53,7 @@ basic-cookies = "0.1.4" bollard = "0.11.0" chrono = { version = "0.4.19", features = ["serde"] } clap = "2.33" +color-eyre = "0.5" cookie_store = "0.15.0" digest = "0.9.0" divrem = "1.0.0" @@ -117,6 +117,9 @@ tokio-tar = { git = "https://github.com/dr-bonez/tokio-tar.git" } tokio-tungstenite = "0.14.0" tokio-util = { version = "0.6.8", features = ["io"] } torut = "0.2.0" +tracing = "0.1" +tracing-subscriber = "0.2" +tracing-futures="0.2" typed-builder = "0.9.1" url = { version = "2.2.2", features = ["serde"] } diff --git a/appmgr/src/action/mod.rs b/appmgr/src/action/mod.rs index b11d1f960..7a4e16041 100644 --- a/appmgr/src/action/mod.rs +++ b/appmgr/src/action/mod.rs @@ -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, )) } diff --git a/appmgr/src/auth.rs b/appmgr/src/auth.rs index bc933a40d..63a13b62d 100644 --- a/appmgr/src/auth.rs +++ b/appmgr/src/auth.rs @@ -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" diff --git a/appmgr/src/backup/mod.rs b/appmgr/src/backup/mod.rs index e24725a62..e6189e8a0 100644 --- a/appmgr/src/backup/mod.rs +++ b/appmgr/src/backup/mod.rs @@ -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) } diff --git a/appmgr/src/bin/embassyd.rs b/appmgr/src/bin/embassyd.rs index eef54d1a1..797636e5f 100644 --- a/appmgr/src/bin/embassyd.rs +++ b/appmgr/src/bin/embassyd.rs @@ -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?; diff --git a/appmgr/src/config/action.rs b/appmgr/src/config/action.rs index 096f77e32..197773d7a 100644 --- a/appmgr/src/config/action.rs +++ b/appmgr/src/config/action.rs @@ -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 { diff --git a/appmgr/src/config/mod.rs b/appmgr/src/config/mod.rs index ddc276211..5b4370b77 100644 --- a/appmgr/src/config/mod.rs +++ b/appmgr/src/config/mod.rs @@ -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() diff --git a/appmgr/src/context/cli.rs b/appmgr/src/context/cli.rs index 263a5b6cc..dd0d89feb 100644 --- a/appmgr/src/context/cli.rs +++ b/appmgr/src/context/cli.rs @@ -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() diff --git a/appmgr/src/context/sdk.rs b/appmgr/src/context/sdk.rs index 96a837c56..3f820d293 100644 --- a/appmgr/src/context/sdk.rs +++ b/appmgr/src/context/sdk.rs @@ -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 { 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)?; diff --git a/appmgr/src/control.rs b/appmgr/src/control.rs index f42352098..261181afa 100644 --- a/appmgr/src/control.rs +++ b/appmgr/src/control.rs @@ -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?; diff --git a/appmgr/src/db/mod.rs b/appmgr/src/db/mod.rs index 453058f7c..63367afea 100644 --- a/appmgr/src/db/mod.rs +++ b/appmgr/src/db/mod.rs @@ -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 diff --git a/appmgr/src/dependencies.rs b/appmgr/src/dependencies.rs index 36e9f8258..ce73e8d07 100644 --- a/appmgr/src/dependencies.rs +++ b/appmgr/src/dependencies.rs @@ -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, ) })? diff --git a/appmgr/src/disk/util.rs b/appmgr/src/disk/util.rs index 05b8ffcb0..8331ddba1 100644 --- a/appmgr/src/disk/util.rs +++ b/appmgr/src/disk/util.rs @@ -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>(path: P) -> Result, 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>(path: P) -> Result, 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, 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, P1: AsRef>( 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, P1: AsRef>( .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(), diff --git a/appmgr/src/error.rs b/appmgr/src/error.rs index 931d5ed71..450598413 100644 --- a/appmgr/src/error.rs +++ b/appmgr/src/error.rs @@ -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, } @@ -138,7 +138,7 @@ impl Display for Error { } } impl Error { - pub fn new>(source: E, kind: ErrorKind) -> Self { + pub fn new>(source: E, kind: ErrorKind) -> Self { Error { source: source.into(), kind, @@ -203,7 +203,7 @@ impl From for Error { } impl From for Error { fn from(e: torut::control::ConnError) -> Self { - Error::new(anyhow!("{:?}", e), ErrorKind::Tor) + Error::new(eyre!("{:?}", e), ErrorKind::Tor) } } impl From for Error { @@ -213,7 +213,7 @@ impl From for Error { } impl From 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 for RpcError { @@ -250,7 +250,7 @@ where } impl ResultExt for Result where - anyhow::Error: From, + color_eyre::eyre::Error: From, { fn with_kind(self, kind: ErrorKind) -> Result { self.map_err(|e| Error { @@ -266,9 +266,9 @@ where ) -> Result { 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)); } }; } diff --git a/appmgr/src/install/mod.rs b/appmgr/src/install/mod.rs index bc618f1c8..856e427d4 100644 --- a/appmgr/src/install/mod.rs +++ b/appmgr/src/install/mod.rs @@ -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 (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( .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( 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>(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>(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>(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>(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: {}", diff --git a/appmgr/src/logs.rs b/appmgr/src/logs.rs index bb8c84895..9f2b54e47 100644 --- a/appmgr/src/logs.rs +++ b/appmgr/src/logs.rs @@ -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()); diff --git a/appmgr/src/manager/mod.rs b/appmgr/src/manager/mod.rs index 14a017786..65c0f60bd 100644 --- a/appmgr/src/manager/mod.rs +++ b/appmgr/src/manager/mod.rs @@ -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) -> Result { 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) -> Result) -> Result 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, ) })?; diff --git a/appmgr/src/middleware/auth.rs b/appmgr/src/middleware/auth.rs index 0b4ceffab..c5477c4a7 100644 --- a/appmgr/src/middleware/auth.rs +++ b/appmgr/src/middleware/auth.rs @@ -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 { } } 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, )); } diff --git a/appmgr/src/middleware/diagnostic.rs b/appmgr/src/middleware/diagnostic.rs index 9f978680e..959b8ea2d 100644 --- a/appmgr/src/middleware/diagnostic.rs +++ b/appmgr/src/middleware/diagnostic.rs @@ -19,7 +19,7 @@ pub async fn diagnostic( 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 ), diff --git a/appmgr/src/middleware/encrypt.rs b/appmgr/src/middleware/encrypt.rs index e18e54ea3..bcfd102e4 100644 --- a/appmgr/src/middleware/encrypt.rs +++ b/appmgr/src/middleware/encrypt.rs @@ -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()), diff --git a/appmgr/src/migration.rs b/appmgr/src/migration.rs index b8e3daa26..6fefdfb82 100644 --- a/appmgr/src/migration.rs +++ b/appmgr/src/migration.rs @@ -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 { diff --git a/appmgr/src/net/interface.rs b/appmgr/src/net/interface.rs index fa6131e2c..fc8d933d0 100644 --- a/appmgr/src/net/interface.rs +++ b/appmgr/src/net/interface.rs @@ -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 { diff --git a/appmgr/src/net/ssl.rs b/appmgr/src/net/ssl.rs index bf4c36808..6dac0d58f 100644 --- a/appmgr/src/net/ssl.rs +++ b/appmgr/src/net/ssl.rs @@ -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 ), diff --git a/appmgr/src/net/tor.rs b/appmgr/src/net/tor.rs index 42d7f9ab6..7997a7f88 100644 --- a/appmgr/src/net/tor.rs +++ b/appmgr/src/net/tor.rs @@ -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, 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(); diff --git a/appmgr/src/net/wifi.rs b/appmgr/src/net/wifi.rs index 95c655710..c3b687ea3 100644 --- a/appmgr/src/net/wifi.rs +++ b/appmgr/src/net/wifi.rs @@ -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 { pub fn country_code_parse(code: &str, _matches: &ArgMatches<'_>) -> Result { CountryCode::for_alpha2(code).or(Err(Error::new( - anyhow::anyhow!("Invalid Country Code: {}", code), + color_eyre::eyre::eyre!("Invalid Country Code: {}", code), ErrorKind::Wifi, ))) } diff --git a/appmgr/src/notifications.rs b/appmgr/src/notifications.rs index 6c23e7b35..82b74cca9 100644 --- a/appmgr/src/notifications.rs +++ b/appmgr/src/notifications.rs @@ -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 for crate::Error { fn from(val: InvalidNotificationLevel) -> Self { Error::new( - anyhow!("Invalid Notification Level: {}", val.0), + eyre!("Invalid Notification Level: {}", val.0), ErrorKind::ParseDbField, ) } diff --git a/appmgr/src/properties.rs b/appmgr/src/properties.rs index bda7ffb6e..5592f0e8d 100644 --- a/appmgr/src/properties.rs +++ b/appmgr/src/properties.rs @@ -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( @@ -39,7 +39,7 @@ pub async fn fetch_properties(ctx: RpcContext, id: PackageId) -> Result) -> Result< .with_kind(crate::ErrorKind::Deserialization)? } else { return Err(Error::new( - anyhow!("manifest not found"), + eyre!("manifest not found"), crate::ErrorKind::Pack, )); }; diff --git a/appmgr/src/setup.rs b/appmgr/src/setup.rs index bb83490de..f63da2b25 100644 --- a/appmgr/src/setup.rs +++ b/appmgr/src/setup.rs @@ -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 { 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, ) })? diff --git a/appmgr/src/sound.rs b/appmgr/src/sound.rs index a1ea7fb12..6a9f8674e 100644 --- a/appmgr/src/sound.rs +++ b/appmgr/src/sound.rs @@ -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, ) })? diff --git a/appmgr/src/ssh.rs b/appmgr/src/ssh.rs index 48b46475d..ed21b5f08 100644 --- a/appmgr/src/ssh.rs +++ b/appmgr/src/ssh.rs @@ -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 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>(pool: &Pool, 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, ) })?; diff --git a/appmgr/src/status/mod.rs b/appmgr/src/status/mod.rs index e7a914358..c94fb3738 100644 --- a/appmgr/src/status/mod.rs +++ b/appmgr/src/status/mod.rs @@ -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 { diff --git a/appmgr/src/system.rs b/appmgr/src/system.rs index d497790b9..5e86b4d93 100644 --- a/appmgr/src/system.rs +++ b/appmgr/src/system.rs @@ -209,7 +209,7 @@ pub async fn metrics( ) -> Result { 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 { .map(|s| { s.parse::().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 { 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 { }; fn get_num_kb(l: &str) -> Result { 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 { } fn ensure_present(a: Option, field: &str) -> Result { 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 { .parse::() .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 { .parse::() .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 { .parse::() .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, ) })?; diff --git a/appmgr/src/update/mod.rs b/appmgr/src/update/mod.rs index 3fad02c69..f61916a8f 100644 --- a/appmgr/src/update/mod.rs +++ b/appmgr/src/update/mod.rs @@ -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>, 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>, 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( async fn check_download(hash_from_header: &str, file_digest: Vec) -> 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, // )); // } diff --git a/appmgr/src/util/io.rs b/appmgr/src/util/io.rs index 900d2128d..f1b599fc1 100644 --- a/appmgr/src/util/io.rs +++ b/appmgr/src/util/io.rs @@ -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) } diff --git a/appmgr/src/util/mod.rs b/appmgr/src/util/mod.rs index 989d3a3fb..62c29763d 100644 --- a/appmgr/src/util/mod.rs +++ b/appmgr/src/util/mod.rs @@ -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 Fut, Fut: Future + Send + 'static mut f: F, cooldown: std::time::Duration, mut shutdown: tokio::sync::broadcast::Receiver>, -) -> 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 Deserialize<'de>>( pub fn parse_duration(arg: &str, _: &ArgMatches<'_>) -> Result { 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 "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, )), }