diff --git a/src/bin/rga-preproc.rs b/src/bin/rga-preproc.rs index fb5cc48..6744785 100644 --- a/src/bin/rga-preproc.rs +++ b/src/bin/rga-preproc.rs @@ -2,6 +2,7 @@ use rga::adapters::*; use rga::preproc::*; use ripgrep_all as rga; +use anyhow::Context; use std::fs::File; fn main() -> anyhow::Result<()> { @@ -20,7 +21,7 @@ fn main() -> anyhow::Result<()> { let cache = if args.no_cache { None } else { - Some(rga::preproc_cache::open()?) + Some(rga::preproc_cache::open().context("could not open cache")?) }; let ai = AdaptInfo { inp: &mut i, diff --git a/src/preproc.rs b/src/preproc.rs index f0f5643..8d61542 100644 --- a/src/preproc.rs +++ b/src/preproc.rs @@ -106,18 +106,26 @@ pub fn rga_preproc(ai: AdaptInfo) -> Result<()> { args.cache_compression_level.try_into().unwrap(), )?); debug!("adapting..."); - adapter.adapt( - AdaptInfo { - line_prefix, - filepath_hint, - is_real_file, - inp, - oup: &mut compbuf, - archive_recursion_depth, - config: PreprocConfig { cache: None, args }, - }, - &detection_reason, - )?; + adapter + .adapt( + AdaptInfo { + line_prefix, + filepath_hint, + is_real_file, + inp, + oup: &mut compbuf, + archive_recursion_depth, + config: PreprocConfig { cache: None, args }, + }, + &detection_reason, + ) + .with_context(|| { + format!( + "adapting {} via {} failed", + filepath_hint.to_string_lossy(), + meta.name + ) + })?; let compressed = compbuf .into_inner() .map_err(|_| "could not finish zstd") // can't use with_context here @@ -138,19 +146,28 @@ pub fn rga_preproc(ai: AdaptInfo) -> Result<()> { )?; Ok(()) } else { + // couldn't open cache debug!("adapting..."); - adapter.adapt( - AdaptInfo { - line_prefix, - filepath_hint, - is_real_file, - inp, - oup, - archive_recursion_depth, - config: PreprocConfig { cache: None, args }, - }, - &detection_reason, - )?; + adapter + .adapt( + AdaptInfo { + line_prefix, + filepath_hint, + is_real_file, + inp, + oup, + archive_recursion_depth, + config: PreprocConfig { cache: None, args }, + }, + &detection_reason, + ) + .with_context(|| { + format!( + "adapting {} via {} without caching failed", + filepath_hint.to_string_lossy(), + meta.name + ) + })?; Ok(()) } } diff --git a/src/preproc_cache.rs b/src/preproc_cache.rs index b80cf88..5c7e07f 100644 --- a/src/preproc_cache.rs +++ b/src/preproc_cache.rs @@ -23,9 +23,9 @@ pub trait PreprocCache { fn open_cache_db() -> Result>> { let app_cache = cachedir::CacheDirConfig::new("rga").get_cache_dir()?; - let db_arc = rkv::Manager::singleton() + rkv::Manager::singleton() .write() - .expect("could not write db manager") + .map_err(|_| format_err!("could not write cache db manager"))? .get_or_create(app_cache.as_path(), |p| { let mut builder = rkv::Rkv::environment_builder(); builder @@ -40,8 +40,7 @@ fn open_cache_db() -> Result>> { .set_max_readers(128); rkv::Rkv::from_env(p, builder) }) - .expect("could not get/create db"); - Ok(db_arc) + .map_err(|e| format_err!("could not get/create cache db: {}", e)) } pub struct LmdbCache {