From 57240aa00d7a8f7cd611654c44bd04cec9192133 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 12 Nov 2021 16:02:32 +0100 Subject: 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. --- src/filters/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/filters') diff --git a/src/filters/mod.rs b/src/filters/mod.rs index 7ab0d42..668c5e1 100644 --- a/src/filters/mod.rs +++ b/src/filters/mod.rs @@ -26,7 +26,7 @@ impl ops::Not for Inclusion { type Output = Self; fn not(self) -> Self::Output { - Inclusion::from_i8(-(self as i8)).unwrap() + Inclusion::from_i8(-(self as i8)).expect("i8 is from pre-existing Inclusion") } } @@ -34,7 +34,7 @@ impl ops::BitAnd for Inclusion { type Output = Self; fn bitand(self, rhs: Inclusion) -> Self::Output { - Inclusion::from_i8((self as i8).min(rhs as i8)).unwrap() + Inclusion::from_i8((self as i8).min(rhs as i8)).expect("i8 is from pre-existing Inclusion") } } @@ -42,7 +42,7 @@ impl ops::BitOr for Inclusion { type Output = Self; fn bitor(self, rhs: Inclusion) -> Self::Output { - Inclusion::from_i8((self as i8).max(rhs as i8)).unwrap() + Inclusion::from_i8((self as i8).max(rhs as i8)).expect("i8 is from pre-existing Inclusion") } } -- cgit v1.2.3