diff options
| author | Linus Färnstrand <linus@mullvad.net> | 2019-04-08 15:54:18 +0200 |
|---|---|---|
| committer | Linus Färnstrand <linus@mullvad.net> | 2019-04-08 17:03:43 +0200 |
| commit | b2b240275e3b2ac0f21d1b26c49699ddd2ef8022 (patch) | |
| tree | 83ec4ee97ce7f2b8c76e79cc8bec27e5c4e6da19 | |
| parent | 1fff193bc1d2694f044716c994c402c907b07826 (diff) | |
| download | mullvadvpn-b2b240275e3b2ac0f21d1b26c49699ddd2ef8022.tar.xz mullvadvpn-b2b240275e3b2ac0f21d1b26c49699ddd2ef8022.zip | |
Update mullvad-daemon::geoip module to not use error-chain
| -rw-r--r-- | Cargo.lock | 1 | ||||
| -rw-r--r-- | mullvad-daemon/Cargo.toml | 1 | ||||
| -rw-r--r-- | mullvad-daemon/src/geoip.rs | 33 | ||||
| -rw-r--r-- | mullvad-daemon/src/lib.rs | 3 |
4 files changed, 24 insertions, 14 deletions
diff --git a/Cargo.lock b/Cargo.lock index 67ee83fc42..fd1a0a8403 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)", 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 e9e986a9ce..7caa1c4951 100644 --- a/mullvad-daemon/src/geoip.rs +++ b/mullvad-daemon/src/geoip.rs @@ -7,14 +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") } - } - foreign_links { - Transport(mullvad_rpc::rest::Error); - 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), } @@ -53,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..021ee2262a 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}, @@ -553,7 +552,7 @@ impl Daemon { geoip::send_location_request(https_handle).map_err(|e| { warn!( "Unable to fetch GeoIP location: {}", - ChainedError::display_chain(&e) + ErrorExt::display_chain(&e) ); }) } |
