aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs28
1 files changed, 15 insertions, 13 deletions
diff --git a/src/main.rs b/src/main.rs
index 27ad285..242e285 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,4 +1,4 @@
-#![feature(trait_alias)]
+#![feature(trait_alias, try_blocks)]
use std::collections::HashMap;
use std::fmt;
use std::fs::{self, File};
@@ -10,7 +10,7 @@ use std::sync::atomic::{AtomicBool, Ordering};
use anyhow::{anyhow, Context, Error, Result};
use chrono::{DateTime, Duration, TimeZone, Utc};
use colored::Colorize;
-use log::debug;
+use log::{debug, error};
use regex::Regex;
use rustyline::Editor;
use structopt::StructOpt;
@@ -253,23 +253,23 @@ pub struct EarlyLogResult {
}
enum ZipWrapper<R: Read + Seek> {
- Raw(Option<R>),
+ Raw(R),
Zipped(zip::ZipArchive<R>),
}
impl<R: Read + Seek> ZipWrapper<R> {
pub fn raw(input: R) -> Self {
- ZipWrapper::Raw(Some(input))
+ ZipWrapper::Raw(input)
}
- pub fn zipped(input: R) -> Self {
- ZipWrapper::Zipped(zip::ZipArchive::new(input).unwrap())
+ pub fn zipped(input: R) -> Result<Self> {
+ Ok(ZipWrapper::Zipped(zip::ZipArchive::new(input)?))
}
- pub fn get_stream<'a>(&'a mut self) -> Box<(dyn Read + 'a)> {
+ pub fn get_stream<'a>(&'a mut self) -> Result<Box<(dyn Read + 'a)>> {
match *self {
- ZipWrapper::Raw(ref mut o) => Box::new(o.take().unwrap()),
- ZipWrapper::Zipped(ref mut z) => Box::new(z.by_index(0).unwrap()),
+ ZipWrapper::Raw(ref mut o) => Ok(Box::new(o)),
+ ZipWrapper::Zipped(ref mut z) => Ok(Box::new(z.by_index(0)?)),
}
}
}
@@ -471,7 +471,9 @@ fn grep(opt: &Opt, filter: &dyn LogFilter) -> Result<bool> {
Ok(None) => (),
Ok(Some(result)) => {
found_something.store(true, Ordering::Relaxed);
- pipeline_ref.push_item(result);
+ if let Err(e) = pipeline_ref.push_item(result) {
+ error!("Error writing item to output: {}", e);
+ }
}
Err(err) => {
debug!("Runtime error while scanning {:?}: {}", entry.path(), err);
@@ -483,7 +485,7 @@ fn grep(opt: &Opt, filter: &dyn LogFilter) -> Result<bool> {
Ok(())
});
result?;
- pipeline.finish();
+ pipeline.finish()?;
Ok(found_something.load(Ordering::Relaxed))
}
@@ -512,11 +514,11 @@ fn search_entry(entry: &DirEntry, filter: &dyn LogFilter) -> Result<Option<LogRe
fn search_file(path: &Path, is_zip: bool, filter: &dyn LogFilter) -> Result<Option<LogResult>> {
let file_stream = BufReader::new(File::open(path)?);
let mut wrapper = if is_zip {
- ZipWrapper::zipped(file_stream)
+ ZipWrapper::zipped(file_stream)?
} else {
ZipWrapper::raw(file_stream)
};
- let mut stream = wrapper.get_stream();
+ let mut stream = wrapper.get_stream()?;
let partial = evtclib::raw::parser::parse_partial_file(&mut stream)?;
let early_log = EarlyLogResult {