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 0000000..68ff7f4 Binary files /dev/null and b/exampledir/encoding/utf16le.txt differ 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 0000000..2bd759d Binary files /dev/null and b/exampledir/encoding/zip.tar.gz differ diff --git a/src/adapters/pdfpages.rs b/src/adapters/pdfpages.rs index 9670221..d4745ba 100644 --- a/src/adapters/pdfpages.rs +++ b/src/adapters/pdfpages.rs @@ -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") diff --git a/src/adapters/sqlite.rs b/src/adapters/sqlite.rs index 520eb6e..09a3af3 100644 --- a/src/adapters/sqlite.rs +++ b/src/adapters/sqlite.rs @@ -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!( 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,