From ff33375fdc93df0c01715e5145ea94ea5f301541 Mon Sep 17 00:00:00 2001 From: Janito Vaqueiro Ferreira Filho Date: Tue, 6 Mar 2018 13:45:58 -0300 Subject: [PATCH] Remove unnecessary error types Executable without parent directory should never happen. In either case, the current working directory is used as a fallback and the error is logged. This is the same procedure used for the resources directory. --- talpid-core/src/tunnel/mod.rs | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/talpid-core/src/tunnel/mod.rs b/talpid-core/src/tunnel/mod.rs index a62363010666..086275f981fc 100644 --- a/talpid-core/src/tunnel/mod.rs +++ b/talpid-core/src/tunnel/mod.rs @@ -26,14 +26,6 @@ mod errors { TunnelMonitoringError { description("Error while setting up or processing events from the VPN tunnel") } - /// Failed to get the current executable path. - ExecutablePathInaccessible { - description("Error while reading current executable path") - } - /// Obtained executable path doesn't have a parent directory. - ExecutableHasNoParentDir { - description("Executable path has no directories") - } /// The OpenVPN plugin was not found. PluginNotFound { description("No OpenVPN plugin found") @@ -199,7 +191,7 @@ impl TunnelMonitor { fn get_plugin_path() -> Result { let library = Self::get_library_name().chain_err(|| ErrorKind::PluginNotFound)?; - let mut path = Self::get_executable_dir().chain_err(|| ErrorKind::PluginNotFound)?; + let mut path = Self::get_executable_dir(); path.push(library); @@ -211,13 +203,20 @@ impl TunnelMonitor { } } - fn get_executable_dir() -> Result { - let exe_path = env::current_exe().chain_err(|| ErrorKind::ExecutablePathInaccessible)?; - - exe_path - .parent() - .map(Path::to_path_buf) - .ok_or(ErrorKind::ExecutableHasNoParentDir.into()) + fn get_executable_dir() -> PathBuf { + match env::current_exe() { + Ok(mut path) => { + path.pop(); + path + } + Err(e) => { + error!( + "Failed finding the install directory. Using working directory: {}", + e + ); + PathBuf::from(".") + } + } } fn get_library_name() -> Result<&'static str> {