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,7 +106,8 @@ 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
|
||||||
|
.adapt(
|
||||||
AdaptInfo {
|
AdaptInfo {
|
||||||
line_prefix,
|
line_prefix,
|
||||||
filepath_hint,
|
filepath_hint,
|
||||||
@ -117,7 +118,14 @@ pub fn rga_preproc(ai: AdaptInfo) -> Result<()> {
|
|||||||
config: PreprocConfig { cache: None, args },
|
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,8 +146,10 @@ pub fn rga_preproc(ai: AdaptInfo) -> Result<()> {
|
|||||||
)?;
|
)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
|
// couldn't open cache
|
||||||
debug!("adapting...");
|
debug!("adapting...");
|
||||||
adapter.adapt(
|
adapter
|
||||||
|
.adapt(
|
||||||
AdaptInfo {
|
AdaptInfo {
|
||||||
line_prefix,
|
line_prefix,
|
||||||
filepath_hint,
|
filepath_hint,
|
||||||
@ -150,7 +160,14 @@ pub fn rga_preproc(ai: AdaptInfo) -> Result<()> {
|
|||||||
config: PreprocConfig { cache: None, args },
|
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