Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deps: remove anyhow dependency #2150

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading