Skip to content

Commit

Permalink
Remove unnecessary error types
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Janito Vaqueiro Ferreira Filho committed Mar 6, 2018
1 parent 6090dc0 commit ff33375
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions talpid-core/src/tunnel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -199,7 +191,7 @@ impl TunnelMonitor {

fn get_plugin_path() -> Result<PathBuf> {
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);

Expand All @@ -211,13 +203,20 @@ impl TunnelMonitor {
}
}

fn get_executable_dir() -> Result<PathBuf> {
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> {
Expand Down

0 comments on commit ff33375

Please sign in to comment.