shorten debug output on failure (#7)

This commit is contained in:
phiresky 2019-06-18 12:14:09 +02:00
parent 29b8f1dee4
commit 9c285670fd
11 changed files with 30 additions and 21 deletions

View File

@ -2,6 +2,7 @@
- Fix file ending regex ([#13](https://github.com/phiresky/ripgrep-all/issues/13))
- Fix decoding of UTF16 with BOM ([#5](https://github.com/phiresky/ripgrep-all/issues/5))
- Shorten the output on failure to two lines (https://github.com/phiresky/ripgrep-all/issues/7), you can use `--no-messages` to completely suppress errors.
# 0.9.1 (2019-06-16)

Binary file not shown.

View File

@ -0,0 +1 @@
hello wörld!

Binary file not shown.

View File

@ -1,12 +1,10 @@
use super::*;
use crate::adapters::spawning::map_exe_error;
use crate::preproc::rga_preproc;
use lazy_static::lazy_static;
use log::*;
use std::fs::File;
use std::io::BufReader;
use std::path::PathBuf;
use std::process::Command;
@ -62,7 +60,7 @@ impl FileAdapter for PdfPagesAdapter {
let exe_name = "gm";
let out_dir = tempfile::Builder::new().prefix("pdfpages-").tempdir()?;
let out_fname = out_dir.path().join("out%04d.png");
eprintln!("writing to temp dir: {}", out_fname.display());
debug!("writing to temp dir: {}", out_fname.display());
let mut cmd = Command::new(exe_name);
cmd.arg("convert")
.arg("-density")

View File

@ -1,6 +1,7 @@
use super::*;
use failure::*;
use lazy_static::lazy_static;
use log::*;
use rusqlite::types::ValueRef;
use rusqlite::*;
use std::convert::TryInto;
@ -79,7 +80,7 @@ impl FileAdapter for SqliteAdapter {
.query_map(NO_PARAMS, |r| r.get::<_, String>(0))?
.filter_map(|e| e.ok())
.collect();
eprintln!("db has {} tables", tables.len());
debug!("db has {} tables", tables.len());
for table in tables {
// can't use query param at that position
let mut sel = conn.prepare(&format!(

View File

@ -3,7 +3,7 @@ use crate::preproc::rga_preproc;
use ::tar::EntryType::Regular;
use failure::*;
use lazy_static::lazy_static;
use log::*;
use std::path::PathBuf;
static EXTENSIONS: &[&str] = &["tar"];
@ -51,7 +51,7 @@ impl FileAdapter for TarAdapter {
let mut file = entry?;
if Regular == file.header().entry_type() {
let path = PathBuf::from(file.path()?.to_owned());
eprintln!(
debug!(
"{}|{}: {} bytes",
filepath_hint.display(),
path.display(),

View File

@ -3,6 +3,7 @@ use crate::preproc::rga_preproc;
use ::zip::read::ZipFile;
use failure::*;
use lazy_static::lazy_static;
use log::*;
// todo:
// maybe todo: read list of extensions from
@ -63,7 +64,7 @@ impl FileAdapter for ZipAdapter {
if is_dir(&file) {
continue;
}
eprintln!(
debug!(
"{}{}|{}: {} bytes ({} bytes packed)",
line_prefix,
filepath_hint.to_string_lossy(),

View File

@ -33,5 +33,11 @@ fn main() -> Fallible<()> {
config: PreprocConfig { cache, args: &args },
};
rga_preproc(ai)
match rga_preproc(ai) {
Ok(()) => Ok(()),
Err(e) => {
eprintln!("preproc error: {}", e);
std::process::exit(1);
}
}
}

View File

@ -49,7 +49,7 @@ impl<W: Write> Write for CachingWriter<W> {
let compressed_len = writer.get_ref().len();
trace!("wrote {} to zstd, len now {}", wrote, compressed_len);
if compressed_len > self.max_cache_size {
eprintln!("cache longer than max, dropping");
debug!("cache longer than max, dropping");
//writer.finish();
self.zstd_writer.take().unwrap().finish()?;
}
@ -60,7 +60,7 @@ impl<W: Write> Write for CachingWriter<W> {
}
}
fn flush(&mut self) -> std::io::Result<()> {
eprintln!("flushing");
debug!("flushing");
if let Some(writer) = self.zstd_writer.as_mut() {
writer.flush()?;
}

View File

@ -4,6 +4,7 @@ use crate::matching::*;
use crate::CachingWriter;
use failure::Fallible;
use failure::{format_err, Error};
use log::*;
use path_clean::PathClean;
use std::convert::TryInto;
use std::io::BufRead;
@ -22,7 +23,7 @@ pub struct PreprocConfig<'a> {
* If a cache is passed, read/write to it.
*
*/
pub fn rga_preproc(ai: AdaptInfo) -> Result<(), Error> {
pub fn rga_preproc(ai: AdaptInfo) -> Fallible<()> {
let AdaptInfo {
filepath_hint,
is_real_file,
@ -38,22 +39,22 @@ pub fn rga_preproc(ai: AdaptInfo) -> Result<(), Error> {
let filename = filepath_hint
.file_name()
.ok_or_else(|| format_err!("Empty filename"))?;
eprintln!("depth: {}", archive_recursion_depth);
debug!("depth: {}", archive_recursion_depth);
if archive_recursion_depth >= args.max_archive_recursion {
writeln!(oup, "{}[rga: max archive recursion reached]", line_prefix)?;
return Ok(());
}
eprintln!("path_hint: {:?}", filepath_hint);
debug!("path_hint: {:?}", filepath_hint);
// todo: figure out when using a bufreader is a good idea and when it is not
// seems to beed for File::open() reads, but not sure about within archives (tar, zip)
// seems to be good for File::open() reads, but not sure about within archives (tar, zip)
let inp = &mut BufReader::with_capacity(1 << 13, inp);
let mimetype = if args.accurate {
let buf = inp.fill_buf()?; // fill but do not consume!
let mimetype = tree_magic::from_u8(buf);
eprintln!("mimetype: {:?}", mimetype);
debug!("mimetype: {:?}", mimetype);
Some(mimetype)
} else {
None
@ -78,14 +79,14 @@ pub fn rga_preproc(ai: AdaptInfo) -> Result<(), Error> {
meta.modified().expect("weird OS that can't into mtime"),
&args.adapters[..],
);
eprintln!("cache key: {:?}", key);
debug!("cache key: {:?}", key);
bincode::serialize(&key).expect("could not serialize path") // key in the cache database
} else {
let key = (
clean_path,
meta.modified().expect("weird OS that can't into mtime"),
);
eprintln!("cache key: {:?}", key);
debug!("cache key: {:?}", key);
bincode::serialize(&key).expect("could not serialize path") // key in the cache database
}
};
@ -99,7 +100,7 @@ pub fn rga_preproc(ai: AdaptInfo) -> Result<(), Error> {
args.cache_max_blob_len.try_into().unwrap(),
args.cache_compression_level.try_into().unwrap(),
)?);
eprintln!("adapting...");
debug!("adapting...");
adapter.adapt(
AdaptInfo {
line_prefix,
@ -118,7 +119,7 @@ pub fn rga_preproc(ai: AdaptInfo) -> Result<(), Error> {
.unwrap()
.finish()?;
if let Some(cached) = compressed {
eprintln!("compressed len: {}", cached.len());
debug!("compressed len: {}", cached.len());
Ok(Some(cached))
} else {
Ok(None)
@ -132,7 +133,7 @@ pub fn rga_preproc(ai: AdaptInfo) -> Result<(), Error> {
)?;
Ok(())
} else {
eprintln!("adapting...");
debug!("adapting...");
adapter.adapt(
AdaptInfo {
line_prefix,