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/paths.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src/paths.rs') diff --git a/src/paths.rs b/src/paths.rs index f219dc4..bebe0ee 100644 --- a/src/paths.rs +++ b/src/paths.rs @@ -4,10 +4,8 @@ use super::APP_NAME; use std::path::PathBuf; /// Returns the path that should be used for the cache. -pub fn cache_path() -> PathBuf { - let mut cache_path = dirs::cache_dir().unwrap(); - cache_path.push(APP_NAME); - cache_path +pub fn cache_path() -> Option { + dirs::cache_dir().map(|p| p.join(APP_NAME)) } /// Returns the path that should be used for the REPL history. -- cgit v1.2.3