summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorLinus Färnstrand <linus@mullvad.net>2019-04-09 08:59:26 +0200
committerLinus Färnstrand <linus@mullvad.net>2019-04-09 08:59:26 +0200
commit88031a653167df93396433fcf53a1422c2f995fd (patch)
tree5cf8ee0e69520f92d0b5180c791fa451b1773548
parent471a3fe5a74c9924b66994175919ff7472e7fdcb (diff)
parent44be4c480845ecb43607dbcdc0e5c497b7eab98a (diff)
downloadmullvadvpn-88031a653167df93396433fcf53a1422c2f995fd.tar.xz
mullvadvpn-88031a653167df93396433fcf53a1422c2f995fd.zip
Merge branch 'eliminate-more-error-chain-ipc'
-rw-r--r--Cargo.lock2
-rw-r--r--mullvad-cli/src/cmds/connect.rs2
-rw-r--r--mullvad-cli/src/main.rs9
-rw-r--r--mullvad-daemon/src/rpc_uniqueness_check.rs4
-rw-r--r--mullvad-ipc-client/Cargo.toml2
-rw-r--r--mullvad-ipc-client/src/lib.rs58
-rw-r--r--mullvad-tests/src/lib.rs4
7 files changed, 19 insertions, 62 deletions
diff --git a/Cargo.lock b/Cargo.lock
index bd4e137f95..9ed21eee69 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1122,7 +1122,7 @@ dependencies = [
name = "mullvad-ipc-client"
version = "0.1.0"
dependencies = [
- "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "err-derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
"jsonrpc-client-core 0.5.0 (git+https://github.com/mullvad/jsonrpc-client-rs?rev=68aac55b)",
"jsonrpc-client-ipc 0.5.0 (git+https://github.com/mullvad/jsonrpc-client-rs?rev=68aac55b)",
diff --git a/mullvad-cli/src/cmds/connect.rs b/mullvad-cli/src/cmds/connect.rs
index 422b207c33..89cc0f2d2e 100644
--- a/mullvad-cli/src/cmds/connect.rs
+++ b/mullvad-cli/src/cmds/connect.rs
@@ -1,5 +1,5 @@
use crate::{new_rpc_client, Command, Result};
-use error_chain::ChainedError;
+use talpid_types::ErrorExt;
pub struct Connect;
diff --git a/mullvad-cli/src/main.rs b/mullvad-cli/src/main.rs
index 389d98506c..e4fde0c211 100644
--- a/mullvad-cli/src/main.rs
+++ b/mullvad-cli/src/main.rs
@@ -12,9 +12,9 @@
extern crate error_chain;
use clap::{crate_authors, crate_description, crate_name};
-use error_chain::ChainedError;
use mullvad_ipc_client::{new_standalone_ipc_client, DaemonRpcClient};
use std::io;
+use talpid_types::ErrorExt;
mod cmds;
@@ -24,7 +24,7 @@ pub const PRODUCT_VERSION: &str = include_str!(concat!(env!("OUT_DIR"), "/produc
error_chain! {
errors {
- DaemonNotRunning(err: mullvad_ipc_client::Error) {
+ DaemonNotRunning(err: io::Error) {
description("Failed to connect to daemon")
display("Failed to connect to daemon: {}Is the daemon running?", err.display_chain())
}
@@ -36,10 +36,7 @@ error_chain! {
foreign_links {
Io(io::Error);
ParseIntError(::std::num::ParseIntError);
- }
-
- links {
- RpcClientError(mullvad_ipc_client::Error, mullvad_ipc_client::ErrorKind);
+ RpcClientError(mullvad_ipc_client::Error);
}
}
diff --git a/mullvad-daemon/src/rpc_uniqueness_check.rs b/mullvad-daemon/src/rpc_uniqueness_check.rs
index 297d11609d..7befdb4ba1 100644
--- a/mullvad-daemon/src/rpc_uniqueness_check.rs
+++ b/mullvad-daemon/src/rpc_uniqueness_check.rs
@@ -1,8 +1,6 @@
-use error_chain::ChainedError;
-
use mullvad_ipc_client::new_standalone_ipc_client;
use mullvad_paths;
-
+use talpid_types::ErrorExt;
/// Checks if there is another instance of the daemon running.
///
diff --git a/mullvad-ipc-client/Cargo.toml b/mullvad-ipc-client/Cargo.toml
index d4c17e1894..2d025418a5 100644
--- a/mullvad-ipc-client/Cargo.toml
+++ b/mullvad-ipc-client/Cargo.toml
@@ -7,7 +7,7 @@ license = "GPL-3.0"
edition = "2018"
[dependencies]
-error-chain = "0.12"
+err-derive = "0.1.5"
mullvad-types = { path = "../mullvad-types" }
serde = "1.0"
talpid-ipc = { path = "../talpid-ipc" }
diff --git a/mullvad-ipc-client/src/lib.rs b/mullvad-ipc-client/src/lib.rs
index f8bccd64c5..c1a205a44f 100644
--- a/mullvad-ipc-client/src/lib.rs
+++ b/mullvad-ipc-client/src/lib.rs
@@ -1,8 +1,5 @@
#![deny(rust_2018_idioms)]
-#[macro_use]
-extern crate error_chain;
-
use futures::sync::oneshot;
use jsonrpc_client_core::{Client, ClientHandle, Future};
use jsonrpc_client_ipc::IpcTransport;
@@ -16,64 +13,32 @@ use mullvad_types::{
DaemonEvent,
};
use serde::{Deserialize, Serialize};
-use std::{path::Path, thread};
+use std::{io, path::Path, thread};
use talpid_types::{
net::{openvpn, wireguard},
tunnel::TunnelStateTransition,
};
-pub use jsonrpc_client_core::{Error as RpcError, ErrorKind as RpcErrorKind};
-
-error_chain! {
- errors {
- AuthenticationError {
- description("Failed to authenticate the connection with the daemon")
- }
-
- RpcCallError(method: String) {
- description("Failed to call RPC method")
- display("Failed to call RPC method \"{}\"", method)
- }
-
- RpcSubscribeError(event: String) {
- description("Failed to subscribe to RPC event")
- display("Failed to subscribe to RPC event \"{}\"", event)
- }
-
- StartRpcClient(address: String) {
- description("Failed to start RPC client")
- display("Failed to start RPC client to {}", address)
- }
-
- TokioError {
- description("Failed to setup a standalone event loop")
- }
-
- TransportError {
- description("Failed to setup a transport")
- }
- }
-}
-
static NO_ARGS: [u8; 0] = [];
+pub type Result<T> = std::result::Result<T, jsonrpc_client_core::Error>;
+pub use jsonrpc_client_core::Error;
-pub fn new_standalone_ipc_client(path: &impl AsRef<Path>) -> Result<DaemonRpcClient> {
+pub fn new_standalone_ipc_client(path: &impl AsRef<Path>) -> io::Result<DaemonRpcClient> {
let path = path.as_ref().to_string_lossy().to_string();
new_standalone_transport(path, |path| {
IpcTransport::new(&path, &tokio::reactor::Handle::default())
- .chain_err(|| ErrorKind::TransportError)
})
}
pub fn new_standalone_transport<
- F: Send + 'static + FnOnce(String) -> Result<T>,
+ F: Send + 'static + FnOnce(String) -> io::Result<T>,
T: jsonrpc_client_core::DuplexTransport + 'static,
>(
rpc_path: String,
transport_func: F,
-) -> Result<DaemonRpcClient> {
+) -> io::Result<DaemonRpcClient> {
let (tx, rx) = oneshot::channel();
thread::spawn(move || match spawn_transport(rpc_path, transport_func) {
Err(e) => tx
@@ -92,7 +57,7 @@ pub fn new_standalone_transport<
}
});
- rx.wait().chain_err(|| ErrorKind::TransportError)?.map(
+ rx.wait().expect("No transport handles returned").map(
|(rpc_client, server_handle, executor)| {
let subscriber =
jsonrpc_client_pubsub::Subscriber::new(executor, rpc_client.clone(), server_handle);
@@ -105,12 +70,12 @@ pub fn new_standalone_transport<
}
fn spawn_transport<
- F: Send + FnOnce(String) -> Result<T>,
+ F: Send + FnOnce(String) -> io::Result<T>,
T: jsonrpc_client_core::DuplexTransport + 'static,
>(
address: String,
transport_func: F,
-) -> Result<(
+) -> io::Result<(
Client<T, jsonrpc_client_core::server::Server>,
jsonrpc_client_core::server::ServerHandle,
ClientHandle,
@@ -245,10 +210,7 @@ impl DaemonRpcClient {
A: Serialize + Send + 'static,
O: for<'de> Deserialize<'de> + Send + 'static,
{
- self.rpc_client
- .call_method(method, args)
- .wait()
- .chain_err(|| ErrorKind::RpcCallError(method.to_owned()))
+ self.rpc_client.call_method(method, args).wait()
}
pub fn daemon_event_subscribe(
diff --git a/mullvad-tests/src/lib.rs b/mullvad-tests/src/lib.rs
index fccb1354ca..08969c1366 100644
--- a/mullvad-tests/src/lib.rs
+++ b/mullvad-tests/src/lib.rs
@@ -4,7 +4,7 @@ use self::{mock_openvpn::MOCK_OPENVPN_ARGS_FILE, platform_specific::*};
use futures::sync::oneshot;
use jsonrpc_client_core::{Future, Transport};
use jsonrpc_client_ipc::IpcTransport;
-use mullvad_ipc_client::{DaemonRpcClient, ResultExt};
+use mullvad_ipc_client::DaemonRpcClient;
use mullvad_paths::resources::API_CA_FILENAME;
use notify::{RawEvent, RecommendedWatcher, RecursiveMode, Watcher};
use std::{
@@ -303,8 +303,8 @@ impl DaemonRunner {
let socket_path: String = self.rpc_socket_path.to_string_lossy().to_string();
mullvad_ipc_client::new_standalone_transport(socket_path, |path| {
IpcTransport::new(&path, &Handle::default())
- .chain_err(|| mullvad_ipc_client::ErrorKind::TransportError)
})
+ .map_err(|e| e.to_string())
.map_err(|e| format!("Failed to construct an RPC client - {}", e))
}