From 9c285670fd128d5f142df170ffc38bda82cf15b5 Mon Sep 17 00:00:00 2001 From: phiresky Date: Tue, 18 Jun 2019 12:14:09 +0200 Subject: [PATCH] shorten debug output on failure (#7) --- CHANGELOG.md | 1 + exampledir/encoding/utf16le.txt | Bin 0 -> 28 bytes exampledir/encoding/utf8.txt | 1 + exampledir/encoding/zip.tar.gz | Bin 0 -> 199 bytes src/adapters/pdfpages.rs | 6 ++---- src/adapters/sqlite.rs | 3 ++- src/adapters/tar.rs | 4 ++-- src/adapters/zip.rs | 3 ++- src/bin/rga-preproc.rs | 8 +++++++- src/caching_writer.rs | 4 ++-- src/preproc.rs | 21 +++++++++++---------- 11 files changed, 30 insertions(+), 21 deletions(-) create mode 100644 exampledir/encoding/utf16le.txt create mode 100644 exampledir/encoding/utf8.txt create mode 100644 exampledir/encoding/zip.tar.gz diff --git a/CHANGELOG.md b/CHANGELOG.md index 3de0a2f..defcb92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/exampledir/encoding/utf16le.txt b/exampledir/encoding/utf16le.txt new file mode 100644 index 0000000000000000000000000000000000000000..68ff7f46cb0145b5c317341d9978a9bb2eccfdab GIT binary patch literal 28 gcmezWFM}bKAqNQa859`G8NM+T0of@GiVR!~0D~q63;+NC literal 0 HcmV?d00001 diff --git a/exampledir/encoding/utf8.txt b/exampledir/encoding/utf8.txt new file mode 100644 index 0000000..4f9531f --- /dev/null +++ b/exampledir/encoding/utf8.txt @@ -0,0 +1 @@ +hello wörld! diff --git a/exampledir/encoding/zip.tar.gz b/exampledir/encoding/zip.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..2bd759dfe0265da5a2c3ea5e43bfed2945165c75 GIT binary patch literal 199 zcmb2|=HTF2!V$~BT$Nd%SCUx7@b>aX-a`fgtq)hvJfzc553Nrh&AulQy|yX-X!4YuHOseiM{;Z?(gTrcJ2%I(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!( diff --git a/src/adapters/tar.rs b/src/adapters/tar.rs index 31119a1..c798b05 100644 --- a/src/adapters/tar.rs +++ b/src/adapters/tar.rs @@ -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(), diff --git a/src/adapters/zip.rs b/src/adapters/zip.rs index 4869662..cbcc27e 100644 --- a/src/adapters/zip.rs +++ b/src/adapters/zip.rs @@ -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(), diff --git a/src/bin/rga-preproc.rs b/src/bin/rga-preproc.rs index 3983218..6360951 100644 --- a/src/bin/rga-preproc.rs +++ b/src/bin/rga-preproc.rs @@ -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); + } + } } diff --git a/src/caching_writer.rs b/src/caching_writer.rs index f681043..86439fd 100644 --- a/src/caching_writer.rs +++ b/src/caching_writer.rs @@ -49,7 +49,7 @@ impl Write for CachingWriter { 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 Write for CachingWriter { } } fn flush(&mut self) -> std::io::Result<()> { - eprintln!("flushing"); + debug!("flushing"); if let Some(writer) = self.zstd_writer.as_mut() { writer.flush()?; } diff --git a/src/preproc.rs b/src/preproc.rs index 55cde94..6ace297 100644 --- a/src/preproc.rs +++ b/src/preproc.rs @@ -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,