summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorLinus Färnstrand <linus@mullvad.net>2019-04-08 17:31:13 +0200
committerLinus Färnstrand <linus@mullvad.net>2019-04-08 17:31:13 +0200
commit471a3fe5a74c9924b66994175919ff7472e7fdcb (patch)
tree2943d6e59e3128f714b275494cc23776b5311a21
parente2bc2596cf130a26ab143a173b79039f01ddb1d1 (diff)
parent96ad11e7fa6f7f4d5bb7e24f1e70fe68d8f3c0e9 (diff)
downloadmullvadvpn-471a3fe5a74c9924b66994175919ff7472e7fdcb.tar.xz
mullvadvpn-471a3fe5a74c9924b66994175919ff7472e7fdcb.zip
Merge branch 'eliminate-more-error-chain'
-rw-r--r--Cargo.lock12
-rw-r--r--mullvad-daemon/Cargo.toml1
-rw-r--r--mullvad-daemon/src/geoip.rs35
-rw-r--r--mullvad-daemon/src/lib.rs24
-rw-r--r--mullvad-rpc/Cargo.toml3
-rw-r--r--mullvad-rpc/src/cached_dns_resolver.rs84
-rw-r--r--mullvad-rpc/src/event_loop.rs14
-rw-r--r--mullvad-rpc/src/lib.rs3
-rw-r--r--mullvad-rpc/src/rest.rs35
-rw-r--r--talpid-core/Cargo.toml4
-rw-r--r--talpid-ipc/tests/ipc-client-server.rs2
11 files changed, 110 insertions, 107 deletions
diff --git a/Cargo.lock b/Cargo.lock
index e42c14056b..bd4e137f95 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1085,6 +1085,7 @@ dependencies = [
"chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)",
"ctrlc 3.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "err-derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"fern 0.5.8 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1170,7 +1171,8 @@ name = "mullvad-rpc"
version = "0.1.0"
dependencies = [
"chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
- "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "derive_more 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "err-derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"filetime 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
"hyper 0.11.27 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2012,7 +2014,7 @@ dependencies = [
"talpid-types 0.1.0",
"tempfile 3.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-core 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
- "tun 0.4.2 (git+https://github.com/pinkisemils/rust-tun?branch=add-raw-fd-traits)",
+ "tun 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
"uuid 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)",
"which 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"widestring 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2396,8 +2398,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "tun"
-version = "0.4.2"
-source = "git+https://github.com/pinkisemils/rust-tun?branch=add-raw-fd-traits#6638b8545a21387eeedf429b64bd24d8447f2832"
+version = "0.4.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"ioctl-sys 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2839,7 +2841,7 @@ dependencies = [
"checksum tokio-uds 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "037ffc3ba0e12a0ab4aca92e5234e0dedeb48fddf6ccd260f1f150a36a9f2445"
"checksum toml 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "758664fc71a3a69038656bee8b6be6477d2a6c315a6b81f7081f591bffa4111f"
"checksum try-lock 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee2aa4715743892880f70885373966c83d73ef1b0838a664ef0c76fffd35e7c2"
-"checksum tun 0.4.2 (git+https://github.com/pinkisemils/rust-tun?branch=add-raw-fd-traits)" = "<none>"
+"checksum tun 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "43a6b6b51530c4ec101fcfbaf7e4b4af958cbadf419ef9e4fb199f7261c6dbec"
"checksum typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "612d636f949607bdf9b123b4a6f6d966dedf3ff669f7f045890d3a4a73948169"
"checksum ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "535c204ee4d8434478593480b8f86ab45ec9aae0e83c568ca81abf0fd0e88f86"
"checksum unicase 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "41d17211f887da8e4a70a45b9536f26fc5de166b81e2d5d80de4a17fd22553bd"
diff --git a/mullvad-daemon/Cargo.toml b/mullvad-daemon/Cargo.toml
index 887419127d..5d252c1217 100644
--- a/mullvad-daemon/Cargo.toml
+++ b/mullvad-daemon/Cargo.toml
@@ -17,6 +17,7 @@ edition = "2018"
chrono = { version = "0.4", features = ["serde"] }
clap = "2.25"
error-chain = "0.12"
+err-derive = "0.1.5"
fern = { version = "0.5", features = ["colored"] }
futures = "0.1"
serde = { version = "1.0", features = ["derive"] }
diff --git a/mullvad-daemon/src/geoip.rs b/mullvad-daemon/src/geoip.rs
index ffd805739b..7caa1c4951 100644
--- a/mullvad-daemon/src/geoip.rs
+++ b/mullvad-daemon/src/geoip.rs
@@ -7,16 +7,23 @@ use serde_json;
const URI_V4: &str = "https://ipv4.am.i.mullvad.net/json";
const URI_V6: &str = "https://ipv6.am.i.mullvad.net/json";
-error_chain! {
- errors {
- NoResponse { description("The request was dropped without any response") }
- }
- links {
- Transport(mullvad_rpc::rest::Error, mullvad_rpc::rest::ErrorKind);
- }
- foreign_links {
- Deserialize(serde_json::error::Error);
- }
+#[derive(err_derive::Error, Debug)]
+pub enum Error {
+ /// Unable to send request to HTTP client.
+ #[error(display = "Unable to send GeoIP request to HTTP client")]
+ SendRequestError,
+
+ /// The request was dropped without any response
+ #[error(display = "The GeoIP request was dropped without any response")]
+ NoResponse,
+
+ /// Error in the HTTP client when requesting GeoIP
+ #[error(display = "Failed to request GeoIP")]
+ Transport(#[error(cause)] mullvad_rpc::rest::Error),
+
+ /// Failed to deserialize GeoIP response
+ #[error(display = "Failed to deserialize GeoIP response")]
+ Deserialize(#[error(cause)] serde_json::error::Error),
}
@@ -55,8 +62,8 @@ fn send_location_request_internal(
let request = mullvad_rpc::rest::create_get_request(uri.parse().unwrap());
futures::Sink::send(request_sender, (request, response_tx))
- .map_err(|e| Error::with_chain(e, ErrorKind::NoResponse))
- .and_then(|_| response_rx.map_err(|e| Error::with_chain(e, ErrorKind::NoResponse)))
- .and_then(|response_result| response_result.map_err(Error::from))
- .and_then(|response| serde_json::from_slice(&response).map_err(Error::from))
+ .map_err(|_| Error::SendRequestError)
+ .and_then(|_| response_rx.map_err(|_| Error::NoResponse))
+ .and_then(|response_result| response_result.map_err(Error::Transport))
+ .and_then(|response| serde_json::from_slice(&response).map_err(Error::Deserialize))
}
diff --git a/mullvad-daemon/src/lib.rs b/mullvad-daemon/src/lib.rs
index 90db136bcb..c76da2fe8d 100644
--- a/mullvad-daemon/src/lib.rs
+++ b/mullvad-daemon/src/lib.rs
@@ -21,7 +21,6 @@ mod relays;
mod rpc_uniqueness_check;
use crate::management_interface::{BoxFuture, ManagementCommand, ManagementInterfaceServer};
-use error_chain::ChainedError;
use futures::{
future,
sync::{mpsc::UnboundedSender, oneshot},
@@ -389,7 +388,7 @@ impl Daemon {
})
});
if let Err(e) = result {
- error!("{}", ErrorExt::display_chain(&e));
+ error!("{}", e.display_chain());
}
}
@@ -551,10 +550,7 @@ impl Daemon {
let https_handle = self.https_handle.clone();
geoip::send_location_request(https_handle).map_err(|e| {
- warn!(
- "Unable to fetch GeoIP location: {}",
- ChainedError::display_chain(&e)
- );
+ warn!("Unable to fetch GeoIP location: {}", e.display_chain());
})
}
@@ -619,7 +615,7 @@ impl Daemon {
}
}
}
- Err(e) => error!("{}", ErrorExt::display_chain(&e)),
+ Err(e) => error!("{}", e.display_chain()),
}
}
@@ -676,7 +672,7 @@ impl Daemon {
self.reconnect_tunnel();
}
}
- Err(e) => error!("{}", ErrorExt::display_chain(&e)),
+ Err(e) => error!("{}", e.display_chain()),
}
}
@@ -691,7 +687,7 @@ impl Daemon {
self.send_tunnel_command(TunnelCommand::AllowLan(allow_lan));
}
}
- Err(e) => error!("{}", ErrorExt::display_chain(&e)),
+ Err(e) => error!("{}", e.display_chain()),
}
}
@@ -714,7 +710,7 @@ impl Daemon {
));
}
}
- Err(e) => error!("{}", ErrorExt::display_chain(&e)),
+ Err(e) => error!("{}", e.display_chain()),
}
}
@@ -728,7 +724,7 @@ impl Daemon {
.notify_settings(self.settings.clone());
}
}
- Err(e) => error!("{}", ErrorExt::display_chain(&e)),
+ Err(e) => error!("{}", e.display_chain()),
}
}
@@ -744,7 +740,7 @@ impl Daemon {
self.reconnect_tunnel();
}
}
- Err(e) => error!("{}", ErrorExt::display_chain(&e)),
+ Err(e) => error!("{}", e.display_chain()),
}
}
@@ -811,7 +807,7 @@ impl Daemon {
self.reconnect_tunnel();
}
}
- Err(e) => error!("{}", ErrorExt::display_chain(&e)),
+ Err(e) => error!("{}", e.display_chain()),
}
}
@@ -827,7 +823,7 @@ impl Daemon {
self.reconnect_tunnel();
}
}
- Err(e) => error!("{}", ErrorExt::display_chain(&e)),
+ Err(e) => error!("{}", e.display_chain()),
}
}
diff --git a/mullvad-rpc/Cargo.toml b/mullvad-rpc/Cargo.toml
index b6e1a25d37..a0c276fbbe 100644
--- a/mullvad-rpc/Cargo.toml
+++ b/mullvad-rpc/Cargo.toml
@@ -8,7 +8,8 @@ edition = "2018"
[dependencies]
chrono = { version = "0.4", features = ["serde"] }
-error-chain = "0.12"
+derive_more = "0.14.0"
+err-derive = "0.1.5"
futures = "0.1.15"
jsonrpc-client-core = "0.5"
jsonrpc-client-http = "0.5"
diff --git a/mullvad-rpc/src/cached_dns_resolver.rs b/mullvad-rpc/src/cached_dns_resolver.rs
index 6f8d152dc6..965948d0c7 100644
--- a/mullvad-rpc/src/cached_dns_resolver.rs
+++ b/mullvad-rpc/src/cached_dns_resolver.rs
@@ -1,45 +1,43 @@
-use error_chain::ChainedError;
use log::{debug, info, warn};
use std::{
- fs::File,
- io::{self, Read, Write},
+ fs::{self, File},
+ io::{self, Write},
net::{IpAddr, ToSocketAddrs},
path::{Path, PathBuf},
sync::mpsc,
thread,
time::{Duration, SystemTime, UNIX_EPOCH},
};
+use talpid_types::ErrorExt;
static DNS_TIMEOUT: Duration = Duration::from_secs(2);
static MAX_CACHE_AGE: Duration = Duration::from_secs(3600);
static EXPIRED_CACHE_TIMESTAMP: SystemTime = UNIX_EPOCH;
-error_chain! {
- errors {
- DnsTimeout(host: String) {
- description("DNS resolution for a host took too long")
- display("DNS resolution for host \"{}\" took too long", host)
- }
+pub type Result<T> = std::result::Result<T, Error>;
- HostNotFound(host: String) {
- description("DNS resolution for a host didn't return any IP addresses")
- display("DNS resolution for host \"{}\" didn't return any IP addresses", host)
- }
+#[derive(err_derive::Error, Debug)]
+pub enum Error {
+ /// DNS resolution for a host took too long
+ #[error(display = "DNS resolution for \"{}\" timed out", _0)]
+ DnsTimeout(String, #[error(cause)] mpsc::RecvTimeoutError),
- InvalidAddress {
- description("Address loaded from file is invalid")
- }
+ /// DNS resolution for a host didn't return any IP addresses
+ #[error(display = "DNS resolution for \"{}\" did not return any IPs", _0)]
+ HostNotFound(String),
- ResolveFailure(host: String) {
- description("Failed to resolve IP address for host")
- display("Failed to resolve IP address for host: {}", host)
- }
- }
+ /// Failed to resolve IP address for host
+ #[error(display = "Failed to resolve IP address for \"{}\"", _0)]
+ ResolveFailure(String, #[error(cause)] io::Error),
- foreign_links {
- FileAccessError(io::Error);
- }
+ /// Unable to read IP cache file
+ #[error(display = "Failed to read DNS IP cache file")]
+ ReadCacheError(#[error(cause)] io::Error),
+
+ /// Address loaded from file is invalid
+ #[error(display = "Address loaded from file is invalid")]
+ ParseCacheError(#[error(cause)] std::net::AddrParseError),
}
@@ -64,10 +62,10 @@ impl SystemDnsResolver {
fn resolve_hostname(host: &str) -> Result<IpAddr> {
(host, 0)
.to_socket_addrs()
- .chain_err(|| ErrorKind::ResolveFailure(host.to_owned()))?
+ .map_err(|e| Error::ResolveFailure(host.to_owned(), e))?
.next()
.map(|socket_address| socket_address.ip())
- .ok_or_else(|| ErrorKind::HostNotFound(host.to_owned()).into())
+ .ok_or_else(|| Error::HostNotFound(host.to_owned()))
}
}
@@ -75,7 +73,7 @@ impl DnsResolver for SystemDnsResolver {
fn resolve(&mut self, host: &str) -> Result<IpAddr> {
Self::resolve_in_background_thread(host)
.recv_timeout(DNS_TIMEOUT)
- .chain_err(|| ErrorKind::DnsTimeout(host.to_owned()))
+ .map_err(|e| Error::DnsTimeout(host.to_owned(), e))
.and_then(|result| result)
}
}
@@ -142,25 +140,19 @@ impl<R: DnsResolver> CachedDnsResolver<R> {
},
Err(error) => {
info!(
- "Failed to load previously cached IP address, using fallback: {}",
- error.display_chain(),
+ "{}",
+ error.display_chain_with_msg(
+ "Failed to load previously cached IP address, using fallback"
+ )
);
-
(fallback_address, EXPIRED_CACHE_TIMESTAMP)
}
}
}
fn load_from_file(file_path: &Path) -> Result<IpAddr> {
- let mut file = File::open(file_path)?;
- let mut address = String::new();
-
- file.read_to_string(&mut address)?;
-
- address
- .trim()
- .parse()
- .chain_err(|| ErrorKind::InvalidAddress)
+ let address = fs::read_to_string(file_path).map_err(Error::ReadCacheError)?;
+ address.trim().parse().map_err(Error::ParseCacheError)
}
fn read_file_modification_time(cache_file: &Path) -> io::Result<SystemTime> {
@@ -190,8 +182,10 @@ impl<R: DnsResolver> CachedDnsResolver<R> {
}
}
Err(e) => {
- let chained_error = e.chain_err(|| format!("Unable to resolve {}", self.hostname));
- warn!("{}", chained_error.display_chain());
+ warn!(
+ "{}",
+ e.display_chain_with_msg(&format!("Unable to resolve {}", self.hostname))
+ );
}
}
}
@@ -462,8 +456,12 @@ mod tests {
impl DnsResolver for MockDnsResolver {
fn resolve(&mut self, host: &str) -> Result<IpAddr> {
self.called.store(true, Ordering::Release);
- self.address
- .ok_or_else(|| ErrorKind::ResolveFailure(host.to_owned()).into())
+ self.address.ok_or_else(|| {
+ Error::ResolveFailure(
+ host.to_owned(),
+ io::Error::new(io::ErrorKind::Other, "FAILED"),
+ )
+ })
}
}
}
diff --git a/mullvad-rpc/src/event_loop.rs b/mullvad-rpc/src/event_loop.rs
index 09af5ed54c..a9181f7527 100644
--- a/mullvad-rpc/src/event_loop.rs
+++ b/mullvad-rpc/src/event_loop.rs
@@ -1,16 +1,10 @@
-use std::thread;
+use std::{io, thread};
use tokio_core::reactor::Core;
-error_chain! {
- errors {
- CoreError { description("Error when creating event loop") }
- }
-}
-
/// Creates a new tokio event loop on a new thread, runs the provided `init` closure on the thread
/// and sends back the result.
/// Used to spawn futures on the core in the separate thread and be able to return sendable handles.
-pub fn create<F, T>(init: F) -> Result<T>
+pub fn create<F, T>(init: F) -> io::Result<T>
where
F: FnOnce(&mut Core) -> T + Send + 'static,
T: Send + 'static,
@@ -28,11 +22,11 @@ where
rx.recv().unwrap()
}
-fn create_core<F, T>(init: F) -> Result<(Core, T)>
+fn create_core<F, T>(init: F) -> io::Result<(Core, T)>
where
F: FnOnce(&mut Core) -> T + Send + 'static,
{
- let mut core = Core::new().chain_err(|| ErrorKind::CoreError)?;
+ let mut core = Core::new()?;
let out = init(&mut core);
Ok((core, out))
}
diff --git a/mullvad-rpc/src/lib.rs b/mullvad-rpc/src/lib.rs
index 51413380e3..4e26bcd125 100644
--- a/mullvad-rpc/src/lib.rs
+++ b/mullvad-rpc/src/lib.rs
@@ -8,9 +8,6 @@
#![deny(rust_2018_idioms)]
-#[macro_use]
-extern crate error_chain;
-
use chrono::{offset::Utc, DateTime};
use jsonrpc_client_core::{expand_params, jsonrpc_client};
use jsonrpc_client_http::{header::Host, HttpTransport, HttpTransportBuilder};
diff --git a/mullvad-rpc/src/rest.rs b/mullvad-rpc/src/rest.rs
index 546aec3b14..76548f0560 100644
--- a/mullvad-rpc/src/rest.rs
+++ b/mullvad-rpc/src/rest.rs
@@ -9,19 +9,26 @@ use hyper_openssl::openssl::error::ErrorStack;
use std::path::Path;
use tokio_core::reactor::Handle;
-error_chain! {
- errors {
- /// When the http status code of the response is not 200 OK
- HttpError(http_code: StatusCode) {
- description("Http error. Server did not return 200 OK")
- display("Http error. Status code {}", http_code)
- }
- }
- foreign_links {
- Hyper(hyper::Error) #[doc = "An error occured in Hyper."];
- Uri(hyper::error::UriError) #[doc = "The string given was not a valid URI."];
- OpenSsl(ErrorStack) #[doc = "Error in OpenSSL"];
- }
+
+pub type Result<T> = std::result::Result<T, Error>;
+
+#[derive(derive_more::From, err_derive::Error, Debug)]
+pub enum Error {
+ /// When the http status code of the response is not 200 OK.
+ #[error(display = "Http error. Status code {}", _0)]
+ HttpError(StatusCode),
+
+ /// An error occured in Hyper.
+ #[error(display = "Error in HTTP client")]
+ Hyper(#[error(cause)] hyper::Error),
+
+ /// The string given was not a valid URI.
+ #[error(display = "Not a valid URI")]
+ Uri(#[error(cause)] hyper::error::UriError),
+
+ /// Error in OpenSSL
+ #[error(display = "Error in OpenSSL")]
+ OpenSsl(#[error(cause)] ErrorStack),
}
@@ -53,7 +60,7 @@ fn create_request_processing_future<CC: hyper::client::Connect>(
if response.status() == hyper::StatusCode::Ok {
future::ok(response)
} else {
- future::err(ErrorKind::HttpError(response.status()).into())
+ future::err(Error::HttpError(response.status()).into())
}
})
.and_then(|response: hyper::Response| response.body().concat2().from_err())
diff --git a/talpid-core/Cargo.toml b/talpid-core/Cargo.toml
index 5c0e57e557..04f8f57bfb 100644
--- a/talpid-core/Cargo.toml
+++ b/talpid-core/Cargo.toml
@@ -46,14 +46,14 @@ nftnl = { git = "https://github.com/mullvad/nftnl-rs", rev = "29651f4370fdf22cc2
mnl = { git = "https://github.com/mullvad/mnl-rs", rev = "f0d19501b9b85be9a1ffaec8317a378bcbdf4fa6", features = ["mnl-1-0-4"] }
which = "2.0"
err-derive = "0.1.5"
-tun = { git = "https://github.com/pinkisemils/rust-tun", branch = "add-raw-fd-traits" }
+tun = "0.4.3"
[target.'cfg(target_os = "macos")'.dependencies]
# TODO: Specify 0.2.1 once the crate gets published
pfctl = { git = "https://github.com/mullvad/pfctl-rs", rev = "9f31b5ddcab941862470075eab83bb398195f3d6" }
system-configuration = "0.2"
-tun = { git = "https://github.com/pinkisemils/rust-tun", branch = "add-raw-fd-traits" }
+tun = "0.4.3"
[target.'cfg(windows)'.dependencies]
diff --git a/talpid-ipc/tests/ipc-client-server.rs b/talpid-ipc/tests/ipc-client-server.rs
index 00caf716f1..6be8349487 100644
--- a/talpid-ipc/tests/ipc-client-server.rs
+++ b/talpid-ipc/tests/ipc-client-server.rs
@@ -74,7 +74,7 @@ fn create_client(ipc_path: String) -> jsonrpc_client_core::ClientHandle {
thread::spawn(move || {
let (client, client_handle) =
- jsonrpc_client_ipc::IpcTransport::new(&ipc_path, &tokio::reactor::Handle::current())
+ jsonrpc_client_ipc::IpcTransport::new(&ipc_path, &tokio::reactor::Handle::default())
.expect("failed to construct a transport")
.into_client();
tx.send(client_handle).unwrap();