diff --git a/Cargo.lock b/Cargo.lock index 4f762e158..8f76fe5c8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -112,9 +112,6 @@ name = "anyhow" version = "1.0.93" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c95c10ba0b00a02636238b814946408b1322d5ac4760326e6fb8ec956d85775" -dependencies = [ - "backtrace", -] [[package]] name = "arbitrary" @@ -161,7 +158,6 @@ dependencies = [ name = "bandwhich" version = "0.23.1" dependencies = [ - "anyhow", "async-trait", "chrono", "clap", @@ -170,6 +166,7 @@ dependencies = [ "clap_mangen", "crossterm", "derive_more", + "eyre", "http_req", "insta", "ipnetwork", @@ -703,6 +700,16 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "eyre" +version = "0.6.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cd915d99f24784cdc19fd37ef22b97e3ff0ae756c7e492e9fbfe897d61e2aec" +dependencies = [ + "indenter", + "once_cell", +] + [[package]] name = "fastrand" version = "2.1.1" @@ -990,6 +997,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 = "2.6.0" diff --git a/Cargo.toml b/Cargo.toml index 5fc30ac81..7589bf4e1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,12 +26,13 @@ default = [] ui_test = [] [dependencies] -anyhow = { version = "1.0.93", features = ["backtrace"] } async-trait = "0.1.83" chrono = "0.4" clap-verbosity-flag = "3.0.1" clap = { version = "4.5.21", features = ["derive"] } crossterm = "0.28.1" +derive_more = { version = "1.0.0", features = ["debug"] } +eyre = "0.6.12" ipnetwork = "0.20.0" itertools = "0.13.0" log = "0.4.22" @@ -46,7 +47,7 @@ tokio = { version = "1.41", features = ["rt", "sync"] } trust-dns-resolver = "0.23.2" unicode-width = "0.2.0" strum = { version = "0.26.3", features = ["derive"] } -derive_more = { version = "1.0.0", features = ["debug"] } + [target.'cfg(any(target_os = "android", target_os = "linux"))'.dependencies] procfs = "0.17.0" @@ -66,12 +67,12 @@ regex = "1.11.1" rstest = "0.23.0" [build-dependencies] -anyhow = "1.0.93" clap = { version = "4.5.21", features = ["derive"] } clap-verbosity-flag = "3.0.1" clap_complete = "4.5.38" clap_mangen = "0.2.24" derive_more = { version = "1.0.0", features = ["debug"] } +eyre = "0.6.12" strum = { version = "0.26.3", features = ["derive"] } [target.'cfg(target_os = "windows")'.build-dependencies] diff --git a/build.rs b/build.rs index 0890ab1b7..8f395b357 100644 --- a/build.rs +++ b/build.rs @@ -1,9 +1,9 @@ use std::{env, fs::File}; -use anyhow::anyhow; use clap::CommandFactory; use clap_complete::Shell; use clap_mangen::Man; +use eyre::eyre; fn main() { build_completion_manpage().unwrap(); @@ -14,13 +14,13 @@ fn main() { include!("src/cli.rs"); -fn build_completion_manpage() -> anyhow::Result<()> { +fn build_completion_manpage() -> eyre::Result<()> { let mut cmd = Opt::command(); // build into `BANDWHICH_GEN_DIR` with a fallback to `OUT_DIR` let gen_dir: PathBuf = env::var_os("BANDWHICH_GEN_DIR") .or_else(|| env::var_os("OUT_DIR")) - .ok_or(anyhow!("OUT_DIR is unset"))? + .ok_or(eyre!("OUT_DIR is unset"))? .into(); // completion @@ -37,7 +37,7 @@ fn build_completion_manpage() -> anyhow::Result<()> { } #[cfg(target_os = "windows")] -fn download_windows_npcap_sdk() -> anyhow::Result<()> { +fn download_windows_npcap_sdk() -> eyre::Result<()> { use std::{ fs, io::{self, Write}, @@ -102,7 +102,7 @@ fn download_windows_npcap_sdk() -> anyhow::Result<()> { "cargo:rustc-link-search=native={}", lib_dir .to_str() - .ok_or(anyhow!("{lib_dir:?} is not valid UTF-8"))? + .ok_or(eyre!("{lib_dir:?} is not valid UTF-8"))? ); Ok(()) diff --git a/src/main.rs b/src/main.rs index bf705f0ea..8ace86fbc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,6 +24,7 @@ use crossterm::{ terminal, }; use display::{elapsed_time, RawTerminalBackend, Ui}; +use eyre::bail; use network::{ dns::{self, IpTable}, LocalSocket, Sniffer, Utilization, @@ -37,7 +38,7 @@ use crate::os::ProcessInfo; const DISPLAY_DELTA: Duration = Duration::from_millis(1000); -fn main() -> anyhow::Result<()> { +fn main() -> eyre::Result<()> { let opts = Opt::parse(); // init logging @@ -59,7 +60,7 @@ fn main() -> anyhow::Result<()> { start(terminal_backend, os_input, opts); } else { let Ok(()) = terminal::enable_raw_mode() else { - anyhow::bail!( + bail!( "Failed to get stdout: if you are trying to pipe 'bandwhich' you should use the --raw flag" ) }; diff --git a/src/network/dns/client.rs b/src/network/dns/client.rs index 0adb7873c..95148172c 100644 --- a/src/network/dns/client.rs +++ b/src/network/dns/client.rs @@ -24,7 +24,7 @@ pub struct Client { } impl Client { - pub fn new(resolver: R, runtime: Runtime) -> anyhow::Result + pub fn new(resolver: R, runtime: Runtime) -> eyre::Result where R: Lookup + Send + Sync + 'static, { diff --git a/src/network/dns/resolver.rs b/src/network/dns/resolver.rs index 8df3fb76d..469954520 100644 --- a/src/network/dns/resolver.rs +++ b/src/network/dns/resolver.rs @@ -15,7 +15,7 @@ pub trait Lookup { pub struct Resolver(TokioAsyncResolver); impl Resolver { - pub async fn new(dns_server: Option) -> anyhow::Result { + pub async fn new(dns_server: Option) -> eyre::Result { let resolver = match dns_server { Some(dns_server_address) => { let mut config = ResolverConfig::new(); diff --git a/src/os/shared.rs b/src/os/shared.rs index e57b6f760..eca3eee5d 100644 --- a/src/os/shared.rs +++ b/src/os/shared.rs @@ -4,8 +4,8 @@ use std::{ time, }; -use anyhow::{anyhow, bail}; use crossterm::event::{read, Event}; +use eyre::{bail, eyre}; use itertools::Itertools; use log::{debug, warn}; use pnet::datalink::{self, Channel::Ethernet, Config, DataLinkReceiver, NetworkInterface}; @@ -99,11 +99,11 @@ pub fn get_input( interface_name: Option<&str>, resolve: bool, dns_server: Option, -) -> anyhow::Result { +) -> eyre::Result { // get the user's requested interface, if any // IDEA: allow requesting multiple interfaces let requested_interfaces = interface_name - .map(|name| get_interface(name).ok_or_else(|| anyhow!("Cannot find interface {name}"))) + .map(|name| get_interface(name).ok_or_else(|| eyre!("Cannot find interface {name}"))) .transpose()? .map(|interface| vec![interface]); @@ -200,7 +200,7 @@ pub fn get_input( let resolver = runtime .block_on(dns::Resolver::new(dns_server)) .map_err(|err| { - anyhow!("Could not initialize the DNS resolver. Are you offline?\n\nReason: {err}") + eyre!("Could not initialize the DNS resolver. Are you offline?\n\nReason: {err}") })?; let dns_client = dns::Client::new(resolver, runtime)?; Some(dns_client)