From b71e2e3c811860ebcf02b755fb3128830d88c852 Mon Sep 17 00:00:00 2001 From: Joel Natividad <1980690+jqnatividad@users.noreply.github.com> Date: Wed, 18 Sep 2024 16:20:54 -0400 Subject: [PATCH] `deps`: remove anyhow dependency --- Cargo.lock | 1 - Cargo.toml | 2 -- src/cmd/geocode.rs | 28 ++++++++++++++++------------ 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2728e2b13..1f158fa64 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5299,7 +5299,6 @@ dependencies = [ "actix-governor", "actix-web", "ahash", - "anyhow", "arboard", "arrow", "assert-json-diff", diff --git a/Cargo.toml b/Cargo.toml index f331daa76..96a484344 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -69,7 +69,6 @@ panic = "abort" [dependencies] ahash = "0.8" -anyhow = { version = "1.0", optional = true } arboard = "3.4.1" arrow = {version = "53", default-features = false, features = ["csv"], optional = true} atoi_simd = "0.16" @@ -358,7 +357,6 @@ fetch = [ ] foreach = ["local-encoding"] geocode = [ - "anyhow", "cached", "geosuggest-core", "geosuggest-utils", diff --git a/src/cmd/geocode.rs b/src/cmd/geocode.rs index 8a14ed7fb..fe4b6a7aa 100644 --- a/src/cmd/geocode.rs +++ b/src/cmd/geocode.rs @@ -592,13 +592,6 @@ enum GeocodeSubCmd { IndexReset, } -// we need this as geosuggest uses anyhow::Error -impl From for CliError { - fn from(err: anyhow::Error) -> CliError { - CliError::Other(format!("Error: {err}")) - } -} - pub fn run(argv: &[&str]) -> CliResult<()> { let mut args: Args = util::get_args(USAGE, argv)?; @@ -790,7 +783,8 @@ async fn geocode_main(args: Args) -> CliResult<()> { filter_languages: languages_vec.clone(), }; - let updater = IndexUpdater::new(indexupdater_settings.clone())?; + let updater = IndexUpdater::new(indexupdater_settings.clone()) + .map_err(|_| CliError::Other("Error initializing IndexUpdater".to_string()))?; let storage = storage::bincode::Storage::new(); @@ -823,7 +817,11 @@ async fn geocode_main(args: Args) -> CliResult<()> { eprintln!("Created at: {created_at}"); match metadata { - Some(m) if updater.has_updates(&m).await? => { + Some(m) + if updater.has_updates(&m).await.map_err(|_| { + CliError::Network("Geonames update check failed.".to_string()) + })? => + { winfo!( "Updates available at Geonames.org. Use `qsv geocode index-update` to \ update/rebuild the index.\nPlease use this judiciously as Geonames \ @@ -860,7 +858,9 @@ async fn geocode_main(args: Args) -> CliResult<()> { "This will take a while as we need to download data & rebuild the index..." ); - let engine = updater.build().await?; + let engine = updater.build().await.map_err(|_| { + CliError::Other("Error building geonames index.".to_string()) + })?; storage .dump_to(geocode_index_file.clone(), &engine) .map_err(|e| format!("{e}"))?; @@ -868,12 +868,16 @@ async fn geocode_main(args: Args) -> CliResult<()> { } else { winfo!("Checking main Geonames website for updates..."); - if updater.has_updates(&metadata.unwrap()).await? { + if updater.has_updates(&metadata.unwrap()).await.map_err(|_| { + CliError::Network("Geonames update check failed.".to_string()) + })? { winfo!( "Updating/Rebuilding Geonames index. This will take a while as we \ need to download data from Geonames & rebuild the index..." ); - let engine = updater.build().await?; + let engine = updater.build().await.map_err(|_| { + CliError::Other("Error updating geonames index.".to_string()) + })?; let _ = storage.dump_to(geocode_index_file.clone(), &engine); winfo!("Updates successfully applied: {geocode_index_file}"); } else {