diff options
author | Daniel <kingdread@gmx.de> | 2021-11-12 16:02:32 +0100 |
---|---|---|
committer | Daniel <kingdread@gmx.de> | 2021-11-12 16:02:32 +0100 |
commit | 57240aa00d7a8f7cd611654c44bd04cec9192133 (patch) | |
tree | 0e748f1f6b64f3787047dffc69c0f4d6a7d83aff /src/output/pipeline.rs | |
parent | 2e2bdac00092f8fcb96283da697a7a820a8c8978 (diff) | |
download | raidgrep-57240aa00d7a8f7cd611654c44bd04cec9192133.tar.gz raidgrep-57240aa00d7a8f7cd611654c44bd04cec9192133.tar.bz2 raidgrep-57240aa00d7a8f7cd611654c44bd04cec9192133.zip |
Better error handling, less .unwraps()
Some of these unwraps are fine to stay, mostly those that deal with
locks - in this case, crashing the program if something goes wrong is
probably fine.
However, we also had a lot of other places where we panic'd on errors,
even though we really shouldn't have. For example, an invalid zip file
would bring down the whole scanner. In this case, we now use proper
Result<>s and we log the error.
Some places stay with unwrap() for now, mainly the code that is rare and
obvious when it goes wrong - such as an overflow in input values. It
could be made nicer, but it is not a priority for now.
Some unwraps() have been changed to expect() to signal why they
shouldn't fail.
Diffstat (limited to 'src/output/pipeline.rs')
-rw-r--r-- | src/output/pipeline.rs | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/output/pipeline.rs b/src/output/pipeline.rs index 9b7f461..3db0d56 100644 --- a/src/output/pipeline.rs +++ b/src/output/pipeline.rs @@ -3,6 +3,8 @@ use super::{aggregators::Aggregator, formats::Format}; use std::{io::Write, sync::Mutex}; +use anyhow::Result; + pub struct Pipeline { format: Box<dyn Format>, aggregator: Box<dyn Aggregator>, @@ -22,13 +24,13 @@ impl Pipeline { } } - pub fn push_item(&self, item: LogResult) { + pub fn push_item(&self, item: LogResult) -> Result<()> { let mut writer = self.writer.lock().unwrap(); - self.aggregator.push_item(item, &*self.format, &mut *writer); + self.aggregator.push_item(item, &*self.format, &mut *writer) } - pub fn finish(self) { + pub fn finish(self) -> Result<()> { let mut writer = self.writer.lock().unwrap(); - self.aggregator.finish(&*self.format, &mut *writer); + self.aggregator.finish(&*self.format, &mut *writer) } } |