shorten debug output on failure (#7)

pull/18/head
phiresky 5 years ago
parent 29b8f1dee4
commit 9c285670fd

@ -2,6 +2,7 @@
- Fix file ending regex ([#13](https://github.com/phiresky/ripgrep-all/issues/13)) - 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)) - 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) # 0.9.1 (2019-06-16)

Binary file not shown.

Binary file not shown.

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

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

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

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

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

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

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

Loading…
Cancel
Save