From cf68f546113eba7e9f84775c302d6d2f880a09d5 Mon Sep 17 00:00:00 2001 From: David Knaack Date: Sat, 27 Mar 2021 16:46:05 +0100 Subject: [PATCH] fix(context): remove unwrap when pwd is unavailable (#2520) --- src/context.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/context.rs b/src/context.rs index 7abea681..8fd0f03d 100644 --- a/src/context.rs +++ b/src/context.rs @@ -66,7 +66,10 @@ impl<'a> Context<'a> { let path = arguments .value_of("path") .map(PathBuf::from) - .unwrap_or_else(|| env::current_dir().expect("Unable to identify current directory")); + .or_else(|| env::current_dir().ok()) + .or_else(|| env::var("PWD").map(PathBuf::from).ok()) + .or_else(|| arguments.value_of("logical_path").map(PathBuf::from)) + .unwrap_or_default(); // Retrive the "logical directory". // If the path argument is not set fall back to the PWD env variable set by many shells @@ -74,12 +77,8 @@ impl<'a> Context<'a> { let logical_path = arguments .value_of("logical_path") .map(PathBuf::from) - .unwrap_or_else(|| { - env::var("PWD").map(PathBuf::from).unwrap_or_else(|err| { - log::debug!("Unable to get path from $PWD: {}", err); - path.clone() - }) - }); + .or_else(|| env::var("PWD").map(PathBuf::from).ok()) + .unwrap_or_else(|| path.clone()); Context::new_with_shell_and_path(arguments, shell, path, logical_path) }