diff options
| author | Linus Färnstrand <linus@mullvad.net> | 2017-03-16 09:52:34 +0100 |
|---|---|---|
| committer | Linus Färnstrand <linus@mullvad.net> | 2017-03-16 09:52:34 +0100 |
| commit | c0d0e813d560958b0e618091cd8bf682e8b70998 (patch) | |
| tree | d6fd62f9a99484254eb5afb4c6d22d8942fdaf55 | |
| parent | f34a0d45dadfc0a7432b8dc76aa0e8cc1e677c01 (diff) | |
| download | mullvadvpn-c0d0e813d560958b0e618091cd8bf682e8b70998.tar.xz mullvadvpn-c0d0e813d560958b0e618091cd8bf682e8b70998.zip | |
Make use of bail! macro in error_chain
| -rw-r--r-- | openvpn_ffi/src/lib.rs | 2 | ||||
| -rw-r--r-- | openvpn_ffi/src/parse.rs | 2 | ||||
| -rw-r--r-- | src/net.rs | 2 | ||||
| -rw-r--r-- | src/process/monitor.rs | 4 | ||||
| -rw-r--r-- | talpid_ipc/src/nop_ipc.rs | 4 | ||||
| -rw-r--r-- | talpid_ipc/src/zmq_ipc.rs | 2 |
6 files changed, 8 insertions, 8 deletions
diff --git a/openvpn_ffi/src/lib.rs b/openvpn_ffi/src/lib.rs index 3c880b2293..31cb94b502 100644 --- a/openvpn_ffi/src/lib.rs +++ b/openvpn_ffi/src/lib.rs @@ -61,7 +61,7 @@ impl OpenVpnPluginEvent { if i >= OpenVpnPluginEvent::Up as c_int && i <= OpenVpnPluginEvent::N as c_int { Ok(unsafe { ::std::mem::transmute_copy::<c_int, OpenVpnPluginEvent>(&i) }) } else { - Err(ErrorKind::InvalidEnumVariant(i).into()) + bail!(ErrorKind::InvalidEnumVariant(i)) } } } diff --git a/openvpn_ffi/src/parse.rs b/openvpn_ffi/src/parse.rs index 096e3ada55..2da10e3ca2 100644 --- a/openvpn_ffi/src/parse.rs +++ b/openvpn_ffi/src/parse.rs @@ -28,7 +28,7 @@ error_chain!{ /// terminated. Likewise, if any string pointed to is not properly null-terminated it may crash. pub unsafe fn string_array(mut ptr: *const *const c_char) -> Result<Vec<String>> { if ptr.is_null() { - Err(ErrorKind::Null.into()) + bail!(ErrorKind::Null); } else { let mut strings = Vec::new(); while !(*ptr).is_null() { diff --git a/src/net.rs b/src/net.rs index fb119ea8af..3701ae641e 100644 --- a/src/net.rs +++ b/src/net.rs @@ -61,7 +61,7 @@ impl RemoteAddr { })?; if address.is_empty() || address.contains(':') { let msg = format!("Invalid IP or domain: \"{}\"", address); - return Err(ErrorKind::AddrParse(msg).into()); + bail!(ErrorKind::AddrParse(msg)); } Ok(RemoteAddr::Domain(address.to_owned(), port)) } diff --git a/src/process/monitor.rs b/src/process/monitor.rs index 070cbdf196..3a6f9fb65f 100644 --- a/src/process/monitor.rs +++ b/src/process/monitor.rs @@ -91,7 +91,7 @@ impl<S: ChildSpawner> ChildMonitor<S> { }); Ok(io) } else { - Err(ErrorKind::InvalidState.into()) + bail!(ErrorKind::InvalidState); } } @@ -116,7 +116,7 @@ impl<S: ChildSpawner> ChildMonitor<S> { running_state.child.kill().chain_err(|| ErrorKind::Kill)?; Ok(()) } else { - Err(ErrorKind::InvalidState.into()) + bail!(ErrorKind::InvalidState); } } } diff --git a/talpid_ipc/src/nop_ipc.rs b/talpid_ipc/src/nop_ipc.rs index 9a767f229d..50d4fae791 100644 --- a/talpid_ipc/src/nop_ipc.rs +++ b/talpid_ipc/src/nop_ipc.rs @@ -12,7 +12,7 @@ pub fn start_new_server<T, F>(_on_message: F) -> Result<IpcServerId> where T: serde::Deserialize + 'static, F: FnMut(Result<T>) + Send + 'static { - Err(ErrorKind::CouldNotStartServer.into()) + bail!(ErrorKind::CouldNotStartServer); } pub struct IpcClient<T> @@ -29,6 +29,6 @@ impl<T> IpcClient<T> } pub fn send(&mut self, _message: &T) -> Result<()> { - Err(ErrorKind::SendError.into()) + bail!(ErrorKind::SendError); } } diff --git a/talpid_ipc/src/zmq_ipc.rs b/talpid_ipc/src/zmq_ipc.rs index 7a9c6759b5..ff29edc312 100644 --- a/talpid_ipc/src/zmq_ipc.rs +++ b/talpid_ipc/src/zmq_ipc.rs @@ -27,7 +27,7 @@ pub fn start_new_server<T, F>(on_message: F) -> Result<IpcServerId> return Ok(connection_string); } } - Err(ErrorKind::CouldNotStartServer.into()) + bail!(ErrorKind::CouldNotStartServer) } fn start_zmq_server(connection_string: &str) -> zmq::Result<zmq::Socket> { |
