Skip to content

Commit

Permalink
Merge pull request #2150 from jqnatividad/remove-anyhow-dependency
Browse files Browse the repository at this point in the history
`deps`: remove anyhow dependency
  • Loading branch information
jqnatividad authored Sep 18, 2024
2 parents 0ce4786 + b71e2e3 commit 97b56c9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -358,7 +357,6 @@ fetch = [
]
foreach = ["local-encoding"]
geocode = [
"anyhow",
"cached",
"geosuggest-core",
"geosuggest-utils",
Expand Down
28 changes: 16 additions & 12 deletions src/cmd/geocode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -592,13 +592,6 @@ enum GeocodeSubCmd {
IndexReset,
}

// we need this as geosuggest uses anyhow::Error
impl From<anyhow::Error> 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)?;

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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 \
Expand Down Expand Up @@ -860,20 +858,26 @@ 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}"))?;
winfo!("Geonames index successfully rebuilt: {geocode_index_file}");
} 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 {
Expand Down

0 comments on commit 97b56c9

Please sign in to comment.