diff --git a/crates/arti-client/Cargo.toml b/crates/arti-client/Cargo.toml index be77744fd..2cc9abc22 100644 --- a/crates/arti-client/Cargo.toml +++ b/crates/arti-client/Cargo.toml @@ -126,7 +126,7 @@ tor-checkable = { path = "../tor-checkable", version = "0.5.1" } tor-circmgr = { path = "../tor-circmgr", version = "0.9.1" } tor-config = { path = "../tor-config", version = "0.9.2" } tor-dirmgr = { path = "../tor-dirmgr", version = "0.10.2", default-features = false, features = ["mmap"] } -tor-error = { path = "../tor-error", version = "0.5.2" } +tor-error = { path = "../tor-error", version = "0.5.2", features = ["tracing"] } tor-guardmgr = { path = "../tor-guardmgr", version = "0.9.1" } tor-hsclient = { path = "../tor-hsclient", version = "0.3.0", optional = true } tor-hscrypto = { path = "../tor-hscrypto", version = "0.3.0", optional = true } diff --git a/crates/arti-client/src/client.rs b/crates/arti-client/src/client.rs index 092c786b6..64d3f9067 100644 --- a/crates/arti-client/src/client.rs +++ b/crates/arti-client/src/client.rs @@ -19,7 +19,7 @@ use tor_config::MutCfg; #[cfg(feature = "bridge-client")] use tor_dirmgr::bridgedesc::BridgeDescMgr; use tor_dirmgr::{DirMgrStore, Timeliness}; -use tor_error::{internal, Bug, ErrorReport}; +use tor_error::{error_report, internal, Bug}; use tor_guardmgr::GuardMgr; use tor_netdir::{params::NetParameters, NetDirProvider}; use tor_persist::{FsStateMgr, StateMgr}; @@ -56,7 +56,7 @@ use std::sync::{Arc, Mutex}; use crate::err::ErrorDetail; use crate::{status, util, TorClientBuilder}; use tor_rtcompat::scheduler::TaskHandle; -use tracing::{debug, error, info}; +use tracing::{debug, info}; /// An active client session on the Tor network. /// @@ -1313,7 +1313,7 @@ async fn tasks_monitor_dormant( chanmgr .set_dormancy(mode.into(), netparams) - .unwrap_or_else(|e| error!("set dormancy: {}", e.report())); + .unwrap_or_else(|e| error_report!(e, "couldn't set dormancy")); // IEFI simplifies handling of exceptional cases, as "never mind, then". #[cfg(feature = "bridge-client")] diff --git a/crates/arti-client/src/util.rs b/crates/arti-client/src/util.rs index 863e7023a..9522f732b 100644 --- a/crates/arti-client/src/util.rs +++ b/crates/arti-client/src/util.rs @@ -1,8 +1,7 @@ //! Utility functions for the rest of the crate. -use tor_error::ErrorReport; +use tor_error::error_report; use tor_persist::StateMgr; -use tracing::error; /// A RAII guard that calls `::unlock` on drop. pub(crate) struct StateMgrUnlockGuard<'a, T: StateMgr + 'a> { @@ -13,7 +12,7 @@ pub(crate) struct StateMgrUnlockGuard<'a, T: StateMgr + 'a> { impl<'a, T: StateMgr + 'a> Drop for StateMgrUnlockGuard<'a, T> { fn drop(&mut self) { if let Err(e) = self.mgr.unlock() { - error!("Failed to unlock state manager: {}", e.report()); + error_report!(e, "Failed to unlock state manager"); } } } diff --git a/crates/arti/Cargo.toml b/crates/arti/Cargo.toml index 29708fc52..a93c49e3c 100644 --- a/crates/arti/Cargo.toml +++ b/crates/arti/Cargo.toml @@ -108,7 +108,7 @@ time = "0.3.18" tokio-crate = { package = "tokio", version = "1.7", optional = true, features = ["signal"] } tokio-util = { version = "0.7.0", features = ["compat"], optional = true } tor-config = { path = "../tor-config", version = "0.9.2" } -tor-error = { path = "../tor-error", version = "0.5.2", default-features = false } +tor-error = { path = "../tor-error", version = "0.5.2", default-features = false, features = ["tracing"] } tor-rpcbase = { path = "../tor-rpcbase", version = "0.1.2", optional = true } tor-rtcompat = { path = "../tor-rtcompat", version = "0.9.1", default-features = false } tor-socksproto = { path = "../tor-socksproto", version = "0.7.2" } diff --git a/crates/arti/src/dns.rs b/crates/arti/src/dns.rs index ca314faf7..83f40f00b 100644 --- a/crates/arti/src/dns.rs +++ b/crates/arti/src/dns.rs @@ -18,7 +18,7 @@ use trust_dns_proto::serialize::binary::{BinDecodable, BinEncodable}; use arti_client::{Error, HasKind, StreamPrefs, TorClient}; use safelog::sensitive as sv; -use tor_error::ErrorReport; +use tor_error::{error_report, warn_report}; use tor_rtcompat::{Runtime, UdpSocket}; use anyhow::{anyhow, Result}; @@ -221,11 +221,7 @@ where // might well do so too. (Many variants of trust_dns_proto's ProtoErrorKind // contain domain names.) Digging into these to be more useful is tiresome, // so just mark the whole response message, and error, as sensitive. - error!( - "Failed to serialize DNS packet: {:?}: {}", - sv(&response), - sv(e.report()) - ); + error_report!(e, "Failed to serialize DNS packet: {:?}", sv(&response)); continue; } }; @@ -256,7 +252,7 @@ pub(crate) async fn run_dns_resolver( info!("Listening on {:?}.", addr); listeners.push(listener); } - Err(e) => warn!("Can't listen on {}: {}", addr, e.report()), + Err(e) => warn_report!(e, "Can't listen on {}", addr), } } // We weren't able to bind any ports: There's nothing to do. @@ -290,7 +286,7 @@ pub(crate) async fn run_dns_resolver( Ok(packet) => packet, Err(err) => { // TODO move crate::socks::accept_err_is_fatal somewhere else and use it here? - warn!("Incoming datagram failed: {}", err.report()); + warn_report!(err, "Incoming datagram failed"); continue; } }; @@ -309,6 +305,7 @@ pub(crate) async fn run_dns_resolver( ) .await; if let Err(e) = res { + // TODO: warn_report does not work on anyhow::Error. warn!("connection exited with error: {}", tor_error::Report(e)); } } diff --git a/crates/arti/src/logging.rs b/crates/arti/src/logging.rs index 2df70c6b8..a7e00aaa4 100644 --- a/crates/arti/src/logging.rs +++ b/crates/arti/src/logging.rs @@ -10,8 +10,8 @@ use std::str::FromStr; use tor_config::impl_standard_builder; use tor_config::{define_list_builder_accessors, define_list_builder_helper}; use tor_config::{CfgPath, ConfigBuildError}; -use tor_error::ErrorReport; -use tracing::{error, warn, Subscriber}; +use tor_error::warn_report; +use tracing::{error, Subscriber}; use tracing_appender::non_blocking::WorkerGuard; use tracing_subscriber::layer::SubscriberExt; use tracing_subscriber::prelude::*; @@ -340,7 +340,7 @@ pub(crate) fn setup_logging( Err(e) => { // We don't need to propagate this error; it isn't the end of // the world if we were unable to disable safe logging. - warn!("Unable to disable safe logging: {}", e.report()); + warn_report!(e, "Unable to disable safe logging"); None } } diff --git a/crates/arti/src/process.rs b/crates/arti/src/process.rs index 3421660b8..5d3b9ffa3 100644 --- a/crates/arti/src/process.rs +++ b/crates/arti/src/process.rs @@ -1,6 +1,5 @@ //! Code to adjust process-related parameters. -use tor_error::ErrorReport; use tracing::error; use crate::ArtiConfig; @@ -17,7 +16,7 @@ use crate::ArtiConfig; pub(crate) fn use_max_file_limit(config: &ArtiConfig) { match rlimit::increase_nofile_limit(config.system.max_files) { Ok(n) => tracing::debug!("Increased process file limit to {}", n), - Err(e) => tracing::warn!("Error while increasing file limit: {}", e.report()), + Err(e) => tor_error::warn_report!(e, "Error while increasing file limit"), } } diff --git a/crates/arti/src/reload_cfg.rs b/crates/arti/src/reload_cfg.rs index 94c9835c7..684ee08b1 100644 --- a/crates/arti/src/reload_cfg.rs +++ b/crates/arti/src/reload_cfg.rs @@ -134,6 +134,7 @@ pub(crate) fn watch_for_config_changes( watcher = None; } } + // TODO: warn_report does not work on anyhow::Error. Err(e) => warn!("Couldn't reload configuration: {}", tor_error::Report(e)), } } @@ -141,6 +142,7 @@ pub(crate) fn watch_for_config_changes( }; match iife() { Ok(()) => debug!("Thread exiting"), + // TODO: warn_report does not work on anyhow::Error. Err(e) => error!("Config reload thread exiting: {}", tor_error::Report(e)), } }); diff --git a/crates/arti/src/socks.rs b/crates/arti/src/socks.rs index 8fe96e6c9..a42df5b2b 100644 --- a/crates/arti/src/socks.rs +++ b/crates/arti/src/socks.rs @@ -15,7 +15,7 @@ use std::sync::Arc; use tracing::{debug, error, info, warn}; use arti_client::{ErrorKind, HasKind, StreamPrefs, TorClient}; -use tor_error::ErrorReport; +use tor_error::warn_report; #[cfg(feature = "rpc")] use tor_rpcbase as rpc; use tor_rtcompat::{Runtime, TcpListener}; @@ -619,7 +619,7 @@ pub(crate) async fn run_socks_proxy( info!("Listening on {:?}.", addr); listeners.push(listener); } - Err(e) => warn!("Can't listen on {}: {}", addr, e.report()), + Err(e) => warn_report!(e, "Can't listen on {}", addr), } } // We weren't able to bind any ports: There's nothing to do. @@ -649,7 +649,7 @@ pub(crate) async fn run_socks_proxy( if accept_err_is_fatal(&err) { return Err(err).context("Failed to receive incoming stream on SOCKS port"); } else { - warn!("Incoming stream failed: {}", err.report()); + warn_report!(err, "Incoming stream failed"); continue; } } @@ -664,6 +664,7 @@ pub(crate) async fn run_socks_proxy( let res = handle_socks_conn(runtime_copy, socks_context, stream, (sock_id, addr.ip())).await; if let Err(e) = res { + // TODO: warn_report doesn't work on anyhow::Error. warn!("connection exited with error: {}", tor_error::Report(e)); } })?; diff --git a/crates/tor-chanmgr/Cargo.toml b/crates/tor-chanmgr/Cargo.toml index d921050aa..ca82d4e1e 100644 --- a/crates/tor-chanmgr/Cargo.toml +++ b/crates/tor-chanmgr/Cargo.toml @@ -50,7 +50,7 @@ thiserror = "1" tor-basic-utils = { path = "../tor-basic-utils", version = "0.7.1" } tor-cell = { path = "../tor-cell", version = "0.12.0" } tor-config = { path = "../tor-config", version = "0.9.2" } -tor-error = { path = "../tor-error", version = "0.5.2" } +tor-error = { path = "../tor-error", version = "0.5.2", features = ["tracing"] } tor-linkspec = { path = "../tor-linkspec", version = "0.8.1" } tor-llcrypto = { path = "../tor-llcrypto", version = "0.5.2" } tor-netdir = { path = "../tor-netdir", version = "0.9.2" } diff --git a/crates/tor-chanmgr/src/lib.rs b/crates/tor-chanmgr/src/lib.rs index 678358085..33847f970 100644 --- a/crates/tor-chanmgr/src/lib.rs +++ b/crates/tor-chanmgr/src/lib.rs @@ -57,11 +57,11 @@ use std::result::Result as StdResult; use std::sync::{Arc, Weak}; use std::time::Duration; use tor_config::ReconfigureError; -use tor_error::ErrorReport; +use tor_error::error_report; use tor_linkspec::{ChanTarget, OwnedChanTarget}; use tor_netdir::{params::NetParameters, NetDirProvider}; use tor_proto::channel::Channel; -use tracing::{debug, error}; +use tracing::debug; use void::{ResultVoidErrExt, Void}; pub use err::Error; @@ -319,8 +319,7 @@ impl ChanMgr { let netdir = netdir.upgrade().ok_or("netdir gone away")?; let netparams = netdir.params(); self_.mgr.update_netparams(netparams).map_err(|e| { - error!("continually_update_channels_config: failed to process! {}", - e.report()); + error_report!(e, "continually_update_channels_config: failed to process!"); "error processing netdir" })?; } diff --git a/crates/tor-chanmgr/src/transport/default.rs b/crates/tor-chanmgr/src/transport/default.rs index de070cb9e..03fef24a0 100644 --- a/crates/tor-chanmgr/src/transport/default.rs +++ b/crates/tor-chanmgr/src/transport/default.rs @@ -6,7 +6,7 @@ use std::{net::SocketAddr, sync::Arc, time::Duration}; use async_trait::async_trait; use futures::{stream::FuturesUnordered, FutureExt, StreamExt, TryFutureExt}; use safelog::sensitive as sv; -use tor_error::{bad_api_usage, ErrorReport}; +use tor_error::bad_api_usage; use tor_linkspec::{ChannelMethod, HasChanMethod, OwnedChanTarget}; use tor_rtcompat::{Runtime, TcpProvider}; use tracing::trace; @@ -112,7 +112,7 @@ async fn connect_to_one( Err((e, a)) => { // We got a failure on one of the streams. Store the error. // TODO(eta): ideally we'd start the next connection attempt immediately. - tracing::warn!("Connection to {} failed: {}", sv(a), e.report()); + tor_error::warn_report!(e, "Connection to {} failed", sv(a)); errors.push((e, a)); } } diff --git a/crates/tor-dirmgr/Cargo.toml b/crates/tor-dirmgr/Cargo.toml index 82ef7f768..50981412c 100644 --- a/crates/tor-dirmgr/Cargo.toml +++ b/crates/tor-dirmgr/Cargo.toml @@ -88,7 +88,7 @@ tor-circmgr = { path = "../tor-circmgr", version = "0.9.1" } tor-config = { path = "../tor-config", version = "0.9.2" } tor-consdiff = { path = "../tor-consdiff", version = "0.5.3" } tor-dirclient = { path = "../tor-dirclient", version = "0.7.2", default-features = false } -tor-error = { path = "../tor-error", version = "0.5.2" } +tor-error = { path = "../tor-error", version = "0.5.2", features = ["tracing"] } tor-guardmgr = { path = "../tor-guardmgr", version = "0.9.1" } tor-llcrypto = { path = "../tor-llcrypto", version = "0.5.2" } tor-netdir = { path = "../tor-netdir", version = "0.9.2" } diff --git a/crates/tor-dirmgr/src/bootstrap.rs b/crates/tor-dirmgr/src/bootstrap.rs index e7bc139e2..41bdc77d9 100644 --- a/crates/tor-dirmgr/src/bootstrap.rs +++ b/crates/tor-dirmgr/src/bootstrap.rs @@ -22,7 +22,7 @@ use futures::channel::oneshot; use futures::FutureExt; use futures::StreamExt; use tor_dirclient::DirResponse; -use tor_error::ErrorReport; +use tor_error::{info_report, warn_report}; use tor_rtcompat::scheduler::TaskSchedule; use tor_rtcompat::Runtime; use tracing::{debug, info, trace, warn}; @@ -144,7 +144,7 @@ fn note_cache_error( _ => source, }; - info!("Marking {:?} as failed: {}", real_source, problem.report()); + info_report!(problem, "Marking {:?} as failed", real_source); circmgr.note_external_failure(real_source.cache_id(), ExternalActivity::DirCache); circmgr.retire_circ(source.unique_circ_id()); } @@ -190,7 +190,7 @@ pub(crate) fn make_consensus_request( } latest => { if let Err(e) = latest { - warn!("Error loading directory metadata: {}", e.report()); + warn_report!(e, "Error loading directory metadata"); } // If we don't have a consensus, then request one that's // "reasonably new". That way, our clock is set far in the @@ -330,7 +330,7 @@ async fn fetch_multiple( ); } } - Err(e) => warn!("error while downloading: {}", e.report()), + Err(e) => warn_report!(e, "error while downloading"), } } @@ -486,12 +486,12 @@ async fn download_attempt( if let Err(e) = &outcome { dirmgr.note_errors(attempt_id, 1); - warn!("error while adding directory info: {}", e.report()); + warn_report!(e, "error while adding directory info"); } propagate_fatal_errors!(outcome); } Err(e) => { - warn!("Error when expanding directory text: {}", e.report()); + warn_report!(e, "Error when expanding directory text"); if let Some(source) = source { n_errors += 1; note_cache_error(dirmgr.circmgr()?.deref(), &source, &e); @@ -610,7 +610,8 @@ pub(crate) async fn download( futures::select_biased! { outcome = download_attempt(&dirmgr, state, parallelism.into(), attempt_id).fuse() => { if let Err(e) = outcome { - warn!(attempt=%attempt_id, "Error while downloading: {}", e.report()); + // TODO: get warn_report! to support `attempt=%attempt_id`? + warn_report!(e, "Error while downloading (attempt {})", attempt_id); propagate_fatal_errors!(Err(e)); continue 'next_attempt; } else { diff --git a/crates/tor-dirmgr/src/bridgedesc.rs b/crates/tor-dirmgr/src/bridgedesc.rs index 4d62e1223..dd9a13045 100644 --- a/crates/tor-dirmgr/src/bridgedesc.rs +++ b/crates/tor-dirmgr/src/bridgedesc.rs @@ -25,8 +25,8 @@ use tor_basic_utils::retry::RetryDelay; use tor_basic_utils::BinaryHeapExt as _; use tor_checkable::{SelfSigned, Timebound}; use tor_circmgr::CircMgr; -use tor_error::{internal, ErrorKind, HasKind}; -use tor_error::{AbsRetryTime, ErrorReport, HasRetryTime, RetryTime}; +use tor_error::{error_report, internal, ErrorKind, HasKind}; +use tor_error::{AbsRetryTime, HasRetryTime, RetryTime}; use tor_guardmgr::bridge::{BridgeConfig, BridgeDesc}; use tor_guardmgr::bridge::{BridgeDescError, BridgeDescEvent, BridgeDescList, BridgeDescProvider}; use tor_netdoc::doc::routerdesc::RouterDesc; @@ -1012,10 +1012,10 @@ impl> Manager { let cache_entry: Option = (|| store()?.lookup_bridgedesc(bridge))() .unwrap_or_else(|err| { - error!( - r#"bridge descriptor cache lookup failed, for "{}": {}"#, + error_report!( + err, + r#"bridge descriptor cache lookup failed, for "{}""#, sensitive(bridge), - err.report(), ); None }); @@ -1112,10 +1112,7 @@ impl> Manager { Ok(()) })() .unwrap_or_else(|err: crate::Error| { - error!( - "failed to cache downloaded bridge descriptor: {}", - err.report(), - ); + error_report!(err, "failed to cache downloaded bridge descriptor",); }); Ok(got) diff --git a/crates/tor-dirmgr/src/lib.rs b/crates/tor-dirmgr/src/lib.rs index e847684ba..3869ca048 100644 --- a/crates/tor-dirmgr/src/lib.rs +++ b/crates/tor-dirmgr/src/lib.rs @@ -75,7 +75,7 @@ pub use retry::{DownloadSchedule, DownloadScheduleBuilder}; use scopeguard::ScopeGuard; use tor_circmgr::CircMgr; use tor_dirclient::SourceInfo; -use tor_error::{into_internal, ErrorReport}; +use tor_error::{info_report, into_internal, warn_report}; use tor_netdir::params::NetParameters; use tor_netdir::{DirEvent, MdReceiver, NetDir, NetDirProvider}; @@ -503,10 +503,7 @@ impl DirMgr { { match e { Error::ManagerDropped => {} - _ => warn!( - "Unrecovered error while waiting for bootstrap: {}", - e.report() - ), + _ => warn_report!(e, "Unrecovered error while waiting for bootstrap",), } } else if let Err(e) = Self::download_forever(dirmgr_weak.clone(), &mut schedule, attempt_id, sender) @@ -514,7 +511,7 @@ impl DirMgr { { match e { Error::ManagerDropped => {} - _ => warn!("Unrecovered error while downloading: {}", e.report()), + _ => warn_report!(e, "Unrecovered error while downloading"), } } }) @@ -682,7 +679,7 @@ impl DirMgr { if let Err(err) = outcome { if state.is_ready(Readiness::Usable) { usable = true; - info!("Unable to completely download a directory: {}. Nevertheless, the directory is usable, so we'll pause for now.", err.report()); + info_report!(err, "Unable to completely download a directory. (Nevertheless, the directory is usable, so we'll pause for now)"); break 'retry_attempt; } @@ -698,9 +695,9 @@ impl DirMgr { } let delay = retry_delay.next_delay(&mut rand::thread_rng()); - warn!( - "Unable to download a usable directory: {}. We will restart in {}.", - err.report(), + warn_report!( + err, + "Unable to download a usable directory. (We will restart in {})", humantime::format_duration(delay), ); { diff --git a/crates/tor-dirmgr/src/state.rs b/crates/tor-dirmgr/src/state.rs index 4f6985dc9..7d83a59af 100644 --- a/crates/tor-dirmgr/src/state.rs +++ b/crates/tor-dirmgr/src/state.rs @@ -17,7 +17,7 @@ use std::mem; use std::sync::{Arc, Mutex}; use std::time::{Duration, SystemTime}; use time::OffsetDateTime; -use tor_error::{internal, ErrorReport}; +use tor_error::{internal, warn_report}; use tor_netdir::{MdReceiver, NetDir, PartialNetDir}; use tor_netdoc::doc::authcert::UncheckedAuthCert; use tor_netdoc::doc::netstatus::Lifetime; @@ -627,11 +627,7 @@ impl DirState for GetCertsState { newcerts.push((cert, cert_text)); } Err(e) => { - warn!( - "Problem with certificate received from {}: {}", - &source, - e.report() - ); + warn_report!(e, "Problem with certificate received from {}", &source); nonfatal_error.get_or_insert(e); } } diff --git a/crates/tor-hsclient/Cargo.toml b/crates/tor-hsclient/Cargo.toml index 29eec8b47..3f010c253 100644 --- a/crates/tor-hsclient/Cargo.toml +++ b/crates/tor-hsclient/Cargo.toml @@ -56,7 +56,7 @@ tor-checkable = { path = "../tor-checkable", version = "0.5.1" } tor-circmgr = { version = "0.9.1", path = "../tor-circmgr", features = ["hs-client"] } tor-config = { path = "../tor-config", version = "0.9.2" } tor-dirclient = { path = "../tor-dirclient", version = "0.7.2", default-features = false, features = ["hs-client"] } -tor-error = { path = "../tor-error", version = "0.5.2" } +tor-error = { path = "../tor-error", version = "0.5.2", features = ["tracing"] } tor-hscrypto = { version = "0.3.0", path = "../tor-hscrypto" } tor-keymgr = { version = "0.1.0", path = "../tor-keymgr", default-features = false } tor-linkspec = { version = "0.8.1", path = "../tor-linkspec", features = ["decode", "verbatim"] } diff --git a/crates/tor-hsclient/src/connect.rs b/crates/tor-hsclient/src/connect.rs index a41b8b3df..9d8a0f6f0 100644 --- a/crates/tor-hsclient/src/connect.rs +++ b/crates/tor-hsclient/src/connect.rs @@ -16,10 +16,10 @@ use rand::Rng; use tor_bytes::Writeable; use tor_cell::relaycell::hs::intro_payload::{self, IntroduceHandshakePayload}; use tor_cell::relaycell::msg::{AnyRelayMsg, Introduce1, Rendezvous2}; -use tor_error::Bug; +use tor_error::{debug_report, warn_report, Bug}; use tor_hscrypto::Subcredential; use tor_proto::circuit::handshake::hs_ntor; -use tracing::{debug, trace, warn}; +use tracing::{debug, trace}; use retry_error::RetryError; use safelog::Sensitive; @@ -32,7 +32,7 @@ use tor_circmgr::build::circparameters_from_netparameters; use tor_circmgr::hspool::{HsCircKind, HsCircPool}; use tor_circmgr::timeouts::Action as TimeoutsAction; use tor_dirclient::request::Requestable as _; -use tor_error::{internal, into_internal, ErrorReport as _}; +use tor_error::{internal, into_internal}; use tor_error::{HasRetryTime as _, RetryTime}; use tor_hscrypto::pk::{HsBlindId, HsClientDescEncKey, HsId, HsIdKey}; use tor_hscrypto::RendCookie; @@ -505,11 +505,11 @@ impl<'c, R: Runtime, M: MocksForConnect> Context<'c, R, M> { { Ok(desc) => break desc, Err(error) => { - debug!( - "failed hsdir desc fetch for {} from {}: {}", + debug_report!( + &error, + "failed hsdir desc fetch for {} from {}", &self.hsid, &relay.id(), - error.report() ); errors.push(tor_error::Report(DescriptorError { hsdir: hsdir_for_error, @@ -903,7 +903,7 @@ impl<'c, R: Runtime, M: MocksForConnect> Context<'c, R, M> { data.insert(id, IptExperience { duration, outcome }); Ok::<_, Bug>(()) })() - .unwrap_or_else(|e| warn!("error recording HS IPT use experience: {}", e.report())); + .unwrap_or_else(|e| warn_report!(e, "error recording HS IPT use experience")); }; match outcome { @@ -914,11 +914,7 @@ impl<'c, R: Runtime, M: MocksForConnect> Context<'c, R, M> { } Ok(None) => return Err(CE::Failed(errors)), Err(error) => { - debug!( - "hs conn to {}: attempt failed: {}", - &self.hsid, - error.report(), - ); + debug_report!(&error, "hs conn to {}: attempt failed", &self.hsid); // Record error outcome in Data, if in fact we involved the IPT // at all. The IPT information is be retrieved from `error`, // since only some of the errors implicate the introduction point. diff --git a/crates/tor-hsclient/src/state.rs b/crates/tor-hsclient/src/state.rs index ea178a7b3..352a2fd9d 100644 --- a/crates/tor-hsclient/src/state.rs +++ b/crates/tor-hsclient/src/state.rs @@ -19,7 +19,7 @@ use tracing::{debug, error, trace}; use safelog::sensitive as sv; use tor_basic_utils::define_accessor_trait; use tor_circmgr::isolation::Isolation; -use tor_error::{internal, Bug, ErrorReport as _}; +use tor_error::{debug_report, error_report, internal, Bug, ErrorReport as _}; use tor_hscrypto::pk::HsId; use tor_netdir::NetDir; use tor_rtcompat::Runtime; @@ -474,19 +474,25 @@ fn obtain_circuit_or_continuation_info( match (got_error, stored) { (Ok::<(), ConnError>(()), Ok::<(), Bug>(())) => {} (Err(got_error), Ok(())) => { - debug!("HS connection failure: {}: {}", hsid, got_error.report(),); + debug_report!(got_error, "HS connection failure for {}", sv(hsid)); + } + (Ok(()), Err(bug)) => { + error_report!( + bug, + "internal error storing built HS circuit for {}", + sv(hsid) + ); + } + (Err(got_error), Err(bug)) => { + // We're reporting two errors, so we'll construct the event + // manually. + error!( + "internal error storing HS connection error for {}: {}; {}", + sv(hsid), + got_error.report(), + bug.report(), + ); } - (Ok(()), Err(bug)) => error!( - "internal error storing built HS circuit for {}: {}", - sv(hsid), - bug.report(), - ), - (Err(got_error), Err(bug)) => error!( - "internal error storing HS connection error for {}: {}; {}", - sv(hsid), - got_error.report(), - bug.report(), - ), }; drop(barrier_send); }; diff --git a/crates/tor-persist/Cargo.toml b/crates/tor-persist/Cargo.toml index 11657764a..99c342f8f 100644 --- a/crates/tor-persist/Cargo.toml +++ b/crates/tor-persist/Cargo.toml @@ -28,7 +28,7 @@ sanitize-filename = "0.4.0" serde = { version = "1.0.103", features = ["derive"] } serde_json = "1.0.50" thiserror = "1" -tor-error = { path = "../tor-error", version = "0.5.2" } +tor-error = { path = "../tor-error", version = "0.5.2", features = ["tracing"] } tracing = "0.1.36" [target.'cfg(not(target_arch = "wasm32"))'.dependencies] diff --git a/crates/tor-persist/src/fs.rs b/crates/tor-persist/src/fs.rs index 8cdaff51b..ac9e504c4 100644 --- a/crates/tor-persist/src/fs.rs +++ b/crates/tor-persist/src/fs.rs @@ -10,8 +10,8 @@ use serde::{de::DeserializeOwned, Serialize}; use std::path::{Path, PathBuf}; use std::sync::{Arc, Mutex}; use std::time::SystemTime; -use tor_error::ErrorReport; -use tracing::{info, warn}; +use tor_error::warn_report; +use tracing::info; /// Implementation of StateMgr that stores state as JSON files on disk. /// @@ -142,11 +142,7 @@ impl FsStateMgr { for fname in clean::files_to_delete(self.inner.statepath.as_path(), now) { info!("Deleting obsolete file {}", fname.anonymize_home()); if let Err(e) = std::fs::remove_file(&fname) { - warn!( - "Unable to delete {}: {}", - fname.anonymize_home(), - e.report() - ); + warn_report!(e, "Unable to delete {}", fname.anonymize_home(),); } } } diff --git a/crates/tor-persist/src/fs/clean.rs b/crates/tor-persist/src/fs/clean.rs index 616223ca3..0740b36a6 100644 --- a/crates/tor-persist/src/fs/clean.rs +++ b/crates/tor-persist/src/fs/clean.rs @@ -6,7 +6,7 @@ use std::{ time::{Duration, SystemTime}, }; -use tor_error::ErrorReport; +use tor_error::warn_report; use tracing::warn; /// Return true if `path` looks like a filename we'd like to remove from our @@ -57,10 +57,10 @@ pub(super) fn files_to_delete(statepath: &Path, now: SystemTime) -> Vec use std::io::ErrorKind as EK; match err.kind() { EK::NotFound => {} - _ => warn!( - "Failed to scan directory {} for obsolete files: {}", + _ => warn_report!( + err, + "Failed to scan directory {} for obsolete files", statepath.display(), - err.report(), ), } }; @@ -84,10 +84,10 @@ pub(super) fn files_to_delete(statepath: &Path, now: SystemTime) -> Vec ); } Err(err) => { - warn!( - "Found obsolete file {} but could not access its modification time: {}", + warn_report!( + err, + "Found obsolete file {} but could not access its modification time", entry.path().display(), - err.report(), ); } } diff --git a/crates/tor-ptmgr/Cargo.toml b/crates/tor-ptmgr/Cargo.toml index 376efbacb..c2e931b90 100644 --- a/crates/tor-ptmgr/Cargo.toml +++ b/crates/tor-ptmgr/Cargo.toml @@ -38,7 +38,7 @@ serde = { version = "1.0.103", features = ["derive"] } thiserror = "1" tor-chanmgr = { version = "0.9.1", path = "../tor-chanmgr", features = ["pt-client"] } tor-config = { version = "0.9.2", path = "../tor-config" } -tor-error = { version = "0.5.2", path = "../tor-error" } +tor-error = { version = "0.5.2", path = "../tor-error", features = ["tracing"] } tor-linkspec = { version = "0.8.1", path = "../tor-linkspec", features = ["pt-client"] } tor-rtcompat = { version = "0.9.1", path = "../tor-rtcompat" } tor-socksproto = { version = "0.7.2", path = "../tor-socksproto" } diff --git a/crates/tor-ptmgr/src/ipc.rs b/crates/tor-ptmgr/src/ipc.rs index 4786f8b14..98c834e4e 100644 --- a/crates/tor-ptmgr/src/ipc.rs +++ b/crates/tor-ptmgr/src/ipc.rs @@ -21,7 +21,7 @@ use std::sync::Arc; use std::time::{Duration, Instant}; use std::{io, thread}; use tor_config::Itertools; -use tor_error::{internal, ErrorReport}; +use tor_error::{internal, warn_report}; use tor_linkspec::PtTransportName; use tor_rtcompat::{Runtime, SleepProviderExt}; use tor_socksproto::SocksVersion; @@ -437,18 +437,14 @@ impl AsyncPtChild { // Kill it. debug!("Sending kill signal to PT {}", ident); if let Err(e) = child.kill() { - warn!("Failed to kill() spawned PT {}: {}", ident, e.report()); + warn_report!(e, "Failed to kill() spawned PT {}", ident); } } Ok(Some(_)) => { debug!("PT {} shut down successfully.", ident); } // It exited. Err(e) => { - warn!( - "Failed to call try_wait() on spawned PT {}: {}", - ident, - e.report() - ); + warn_report!(e, "Failed to call try_wait() on spawned PT {}", ident); } } }); diff --git a/crates/tor-ptmgr/src/lib.rs b/crates/tor-ptmgr/src/lib.rs index effddbb9b..330b4afe6 100644 --- a/crates/tor-ptmgr/src/lib.rs +++ b/crates/tor-ptmgr/src/lib.rs @@ -56,10 +56,10 @@ use std::future::Future; use std::path::{Path, PathBuf}; use std::pin::Pin; use std::sync::{Arc, RwLock}; -use tor_error::ErrorReport; +use tor_error::error_report; use tor_linkspec::PtTransportName; use tor_rtcompat::Runtime; -use tracing::{debug, error, info, trace, warn}; +use tracing::{debug, info, trace, warn}; #[cfg(feature = "tor-channel-factory")] use { async_trait::async_trait, @@ -339,7 +339,7 @@ impl PtMgr { Ok(true) => return, Ok(false) => {} Err(e) => { - error!("PtReactor failed: {}", e.report()); + error_report!(e, "PtReactor failed"); return; } }