fix: reduce the amount of wrap_err

This commit is contained in:
monosans
2025-09-26 17:13:16 +03:00
parent c9d2227d5b
commit 6241eea6b8
4 changed files with 17 additions and 38 deletions
+4 -7
View File
@@ -71,7 +71,6 @@ mod utils;
use std::sync::Arc;
use color_eyre::eyre::WrapErr as _;
use tracing_subscriber::{
layer::SubscriberExt as _, util::SubscriberInitExt as _,
};
@@ -158,7 +157,7 @@ async fn download_output_dependencies(
}
while let Some(task) = output_dependencies_tasks.join_next().await {
task.wrap_err("output dependencies task panicked or was cancelled")??;
task??;
}
Ok(())
}
@@ -272,15 +271,13 @@ async fn run_with_tui(
config: Arc<config::Config>,
logging_filter: tracing_subscriber::filter::Targets,
) -> crate::Result<()> {
tui_logger::init_logger(tui_logger::LevelFilter::Debug)
.wrap_err("failed to initialize tui_logger")?;
tui_logger::init_logger(tui_logger::LevelFilter::Debug)?;
tracing_subscriber::registry()
.with(logging_filter)
.with(tui_logger::TuiTracingSubscriberLayer)
.init();
let terminal =
ratatui::try_init().wrap_err("failed to initialize ratatui")?;
let terminal = ratatui::try_init()?;
let terminal_guard = tui::RatatuiRestoreGuard;
let token = tokio_util::sync::CancellationToken::new();
@@ -325,7 +322,7 @@ async fn main() -> crate::Result<()> {
#[cfg(feature = "dhat")]
let _profiler = dhat::Profiler::new_heap();
color_eyre::install().wrap_err("failed to install color_eyre hooks")?;
color_eyre::install()?;
let config = config::load_config().await?;
let logging_filter = create_logging_filter(&config);
+10 -26
View File
@@ -105,17 +105,10 @@ pub async fn save_proxies(
exit_ip: proxy.exit_ip.as_deref(),
asn: if let Some(asn_db) = &maybe_asn_db {
if let Some(exit_ip) = proxy.exit_ip.as_ref() {
let exit_ip_addr: IpAddr = exit_ip.parse().wrap_err(
"failed to parse proxy's exit ip as IpAddr",
)?;
asn_db
.lookup::<maxminddb::geoip2::Asn<'_>>(exit_ip_addr)
.wrap_err_with(move || {
format!(
"failed to lookup {exit_ip_addr} in ASN \
database"
)
})?
let exit_ip_addr: IpAddr = exit_ip.parse()?;
asn_db.lookup::<maxminddb::geoip2::Asn<'_>>(
exit_ip_addr,
)?
} else {
None
}
@@ -124,17 +117,10 @@ pub async fn save_proxies(
},
geolocation: if let Some(geo_db) = &maybe_geo_db {
if let Some(exit_ip) = proxy.exit_ip.as_ref() {
let exit_ip_addr: IpAddr = exit_ip.parse().wrap_err(
"failed to parse proxy's exit ip as IpAddr",
)?;
geo_db
.lookup::<maxminddb::geoip2::City<'_>>(exit_ip_addr)
.wrap_err_with(move || {
format!(
"failed to lookup {exit_ip_addr} in \
geolocation database"
)
})?
let exit_ip_addr: IpAddr = exit_ip.parse()?;
geo_db.lookup::<maxminddb::geoip2::City<'_>>(
exit_ip_addr,
)?
} else {
None
}
@@ -156,11 +142,9 @@ pub async fn save_proxies(
}),
}?;
let json_data = if pretty {
serde_json::to_vec_pretty(&proxy_dicts)
.wrap_err("failed to serialize proxies to pretty json")?
serde_json::to_vec_pretty(&proxy_dicts)?
} else {
serde_json::to_vec(&proxy_dicts)
.wrap_err("failed to serialize proxies to json")?
serde_json::to_vec(&proxy_dicts)?
};
tokio::fs::write(&path, json_data).await.wrap_err_with(
move || {
+2 -3
View File
@@ -1,6 +1,6 @@
use std::sync::Arc;
use color_eyre::eyre::{OptionExt as _, WrapErr as _};
use color_eyre::eyre::OptionExt as _;
use foldhash::HashSetExt as _;
#[cfg(feature = "tui")]
@@ -190,8 +190,7 @@ pub async fn scrape_all(
drop(tx);
while let Some(res) = join_set.join_next().await {
res.wrap_err("proxy scraping task panicked or was cancelled")?
.wrap_err("proxy scraping task failed")?;
res??;
}
drop(join_set);
+1 -2
View File
@@ -52,8 +52,7 @@ pub async fn run(
if let Some(event) = rx.recv().await {
if handle_event(event, &mut app_state, &token, &logger_state) {
terminal
.draw(|frame| draw(frame, &app_state, &logger_state))
.wrap_err("failed to draw tui")?;
.draw(|frame| draw(frame, &app_state, &logger_state))?;
}
} else {
break;