mirror of
https://github.com/FliegendeWurst/ripgrep-all.git
synced 2024-11-24 12:24:56 +00:00
better errors
This commit is contained in:
parent
f2d9393832
commit
cb6ad328a2
@ -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,
|
||||
|
@ -106,7 +106,8 @@ pub fn rga_preproc(ai: AdaptInfo) -> Result<()> {
|
||||
args.cache_compression_level.try_into().unwrap(),
|
||||
)?);
|
||||
debug!("adapting...");
|
||||
adapter.adapt(
|
||||
adapter
|
||||
.adapt(
|
||||
AdaptInfo {
|
||||
line_prefix,
|
||||
filepath_hint,
|
||||
@ -117,7 +118,14 @@ pub fn rga_preproc(ai: AdaptInfo) -> Result<()> {
|
||||
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,8 +146,10 @@ pub fn rga_preproc(ai: AdaptInfo) -> Result<()> {
|
||||
)?;
|
||||
Ok(())
|
||||
} else {
|
||||
// couldn't open cache
|
||||
debug!("adapting...");
|
||||
adapter.adapt(
|
||||
adapter
|
||||
.adapt(
|
||||
AdaptInfo {
|
||||
line_prefix,
|
||||
filepath_hint,
|
||||
@ -150,7 +160,14 @@ pub fn rga_preproc(ai: AdaptInfo) -> Result<()> {
|
||||
config: PreprocConfig { cache: None, args },
|
||||
},
|
||||
&detection_reason,
|
||||
)?;
|
||||
)
|
||||
.with_context(|| {
|
||||
format!(
|
||||
"adapting {} via {} without caching failed",
|
||||
filepath_hint.to_string_lossy(),
|
||||
meta.name
|
||||
)
|
||||
})?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -23,9 +23,9 @@ pub trait PreprocCache {
|
||||
fn open_cache_db() -> Result<std::sync::Arc<std::sync::RwLock<rkv::Rkv>>> {
|
||||
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<std::sync::Arc<std::sync::RwLock<rkv::Rkv>>> {
|
||||
.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 {
|
||||
|
Loading…
Reference in New Issue
Block a user