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