diff options
| author | David Lönnhager <david.l@mullvad.net> | 2021-01-28 13:28:44 +0100 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2021-01-28 13:28:44 +0100 |
| commit | e0b5655614cf2b65cffd136b22106e547b15fb7c (patch) | |
| tree | 64c9fde6bc58b6ee2294c6e49e5b288f8dcc5ba4 /mullvad-cli | |
| parent | 115099777c1ca93048cf46ef5cfbb253475bc573 (diff) | |
| parent | b0e5a1ec09dae40501c6ef4450852436020b86f8 (diff) | |
| download | mullvadvpn-e0b5655614cf2b65cffd136b22106e547b15fb7c.tar.xz mullvadvpn-e0b5655614cf2b65cffd136b22106e547b15fb7c.zip | |
Merge branch 'improve-ipc-errors'
Diffstat (limited to 'mullvad-cli')
| -rw-r--r-- | mullvad-cli/src/cmds/account.rs | 5 | ||||
| -rw-r--r-- | mullvad-cli/src/cmds/bridge.rs | 8 | ||||
| -rw-r--r-- | mullvad-cli/src/cmds/relay.rs | 10 | ||||
| -rw-r--r-- | mullvad-cli/src/cmds/reset.rs | 13 | ||||
| -rw-r--r-- | mullvad-cli/src/cmds/status.rs | 2 | ||||
| -rw-r--r-- | mullvad-cli/src/cmds/tunnel.rs | 8 | ||||
| -rw-r--r-- | mullvad-cli/src/cmds/version.rs | 14 | ||||
| -rw-r--r-- | mullvad-cli/src/main.rs | 25 | ||||
| -rw-r--r-- | mullvad-cli/src/state.rs | 4 |
9 files changed, 65 insertions, 24 deletions
diff --git a/mullvad-cli/src/cmds/account.rs b/mullvad-cli/src/cmds/account.rs index f68e2a12eb..0dba7600ce 100644 --- a/mullvad-cli/src/cmds/account.rs +++ b/mullvad-cli/src/cmds/account.rs @@ -91,7 +91,8 @@ impl Account { println!("Mullvad account: {}", settings.account_token); let expiry = rpc .get_account_data(settings.account_token) - .await? + .await + .map_err(|error| Error::RpcFailedExt("Failed to fetch account data", error))? .into_inner(); println!( "Expires at : {}", @@ -132,7 +133,7 @@ impl Account { Code::NotFound | Code::ResourceExhausted => { eprintln!("Failed to submit voucher: {}", err.message()); } - _ => return Err(Error::GrpcClientError(err)), + _ => return Err(Error::RpcFailed(err)), } std::process::exit(1); } diff --git a/mullvad-cli/src/cmds/bridge.rs b/mullvad-cli/src/cmds/bridge.rs index 4bb85b4060..9a674069a8 100644 --- a/mullvad-cli/src/cmds/bridge.rs +++ b/mullvad-cli/src/cmds/bridge.rs @@ -1,4 +1,4 @@ -use crate::{location, new_rpc_client, Command, Result}; +use crate::{location, new_rpc_client, Command, Error, Result}; use clap::value_t; use mullvad_management_interface::types::{ @@ -404,7 +404,11 @@ impl Bridge { async fn list_bridge_relays() -> Result<()> { let mut rpc = new_rpc_client().await?; - let mut locations = rpc.get_relay_locations(()).await?.into_inner(); + let mut locations = rpc + .get_relay_locations(()) + .await + .map_err(|error| Error::RpcFailedExt("Failed to obtain relay locations", error))? + .into_inner(); let mut countries = Vec::new(); diff --git a/mullvad-cli/src/cmds/relay.rs b/mullvad-cli/src/cmds/relay.rs index ab1ea41fe1..e8783e04f3 100644 --- a/mullvad-cli/src/cmds/relay.rs +++ b/mullvad-cli/src/cmds/relay.rs @@ -193,7 +193,9 @@ impl Command for Relay { impl Relay { async fn update_constraints(&self, update: RelaySettingsUpdate) -> Result<()> { let mut rpc = new_rpc_client().await?; - rpc.update_relay_settings(update).await?; + rpc.update_relay_settings(update) + .await + .map_err(|error| Error::RpcFailedExt("Failed to update relay settings", error))?; println!("Relay constraints updated"); Ok(()) } @@ -680,7 +682,11 @@ impl Relay { async fn get_filtered_relays() -> Result<Vec<RelayListCountry>> { let mut rpc = new_rpc_client().await?; - let mut locations = rpc.get_relay_locations(()).await?.into_inner(); + let mut locations = rpc + .get_relay_locations(()) + .await + .map_err(|error| Error::RpcFailedExt("Failed to obtain relay locations", error))? + .into_inner(); let mut countries = Vec::new(); diff --git a/mullvad-cli/src/cmds/reset.rs b/mullvad-cli/src/cmds/reset.rs index bb10a3f0fe..1be34a0ab0 100644 --- a/mullvad-cli/src/cmds/reset.rs +++ b/mullvad-cli/src/cmds/reset.rs @@ -1,4 +1,4 @@ -use crate::{new_rpc_client, Command, Result}; +use crate::{new_rpc_client, Command, Error, Result}; use std::io::stdin; pub struct Reset; @@ -15,12 +15,11 @@ impl Command for Reset { async fn run(&self, _: &clap::ArgMatches<'_>) -> Result<()> { let mut rpc = new_rpc_client().await?; if Self::receive_confirmation() { - if rpc.factory_reset(()).await.is_err() { - eprintln!("FAILED TO PERFORM FACTORY RESET"); - } else { - #[cfg(target_os = "linux")] - println!("If you're running systemd, to remove all logs, you must use journalctl"); - } + rpc.factory_reset(()) + .await + .map_err(|error| Error::RpcFailedExt("FAILED TO PERFORM FACTORY RESET", error))?; + #[cfg(target_os = "linux")] + println!("If you're running systemd, to remove all logs, you must use journalctl"); } Ok(()) } diff --git a/mullvad-cli/src/cmds/status.rs b/mullvad-cli/src/cmds/status.rs index 76a4ed2e67..f4e943cb3c 100644 --- a/mullvad-cli/src/cmds/status.rs +++ b/mullvad-cli/src/cmds/status.rs @@ -97,7 +97,7 @@ async fn print_location(rpc: &mut ManagementServiceClient) -> Result<()> { println!("Location data unavailable"); return Ok(()); } else { - return Err(Error::GrpcClientError(status)); + return Err(Error::RpcFailed(status)); } } }; diff --git a/mullvad-cli/src/cmds/tunnel.rs b/mullvad-cli/src/cmds/tunnel.rs index 53a329af13..4af0864ddf 100644 --- a/mullvad-cli/src/cmds/tunnel.rs +++ b/mullvad-cli/src/cmds/tunnel.rs @@ -187,7 +187,7 @@ impl Tunnel { if status.code() == mullvad_management_interface::Code::NotFound { None } else { - return Err(Error::GrpcClientError(status)); + return Err(Error::RpcFailedExt("Failed to obtain key", status)); } } }; @@ -202,7 +202,11 @@ impl Tunnel { return Ok(()); } - let is_valid = rpc.verify_wireguard_key(()).await?.into_inner(); + let is_valid = rpc + .verify_wireguard_key(()) + .await + .map_err(|error| Error::RpcFailedExt("Failed to verify key", error))? + .into_inner(); println!("Key is valid for use with current account: {}", is_valid); Ok(()) } diff --git a/mullvad-cli/src/cmds/version.rs b/mullvad-cli/src/cmds/version.rs index 06855212bf..08944f921b 100644 --- a/mullvad-cli/src/cmds/version.rs +++ b/mullvad-cli/src/cmds/version.rs @@ -1,4 +1,4 @@ -use crate::{new_rpc_client, Command, Result}; +use crate::{new_rpc_client, Command, Error, Result}; pub struct Version; @@ -15,9 +15,17 @@ impl Command for Version { async fn run(&self, _: &clap::ArgMatches<'_>) -> Result<()> { let mut rpc = new_rpc_client().await?; - let current_version = rpc.get_current_version(()).await?.into_inner(); + let current_version = rpc + .get_current_version(()) + .await + .map_err(|error| Error::RpcFailedExt("Failed to obtain current version", error))? + .into_inner(); println!("Current version: {}", current_version); - let version_info = rpc.get_version_info(()).await?.into_inner(); + let version_info = rpc + .get_version_info(()) + .await + .map_err(|error| Error::RpcFailedExt("Failed to obtain version info", error))? + .into_inner(); println!("\tIs supported: {}", version_info.supported); if !version_info.suggested_upgrade.is_empty() { diff --git a/mullvad-cli/src/main.rs b/mullvad-cli/src/main.rs index 7f93e17222..20dfae5fc9 100644 --- a/mullvad-cli/src/main.rs +++ b/mullvad-cli/src/main.rs @@ -25,8 +25,14 @@ pub enum Error { #[error(display = "Management interface error")] ManagementInterfaceError(#[error(source)] mullvad_management_interface::Error), - #[error(display = "Failed to communicate with mullvad-daemon over RPC")] - GrpcClientError(#[error(source)] mullvad_management_interface::Status), + #[error(display = "RPC failed")] + RpcFailed(#[error(source)] mullvad_management_interface::Status), + + #[error(display = "RPC failed: {}", _0)] + RpcFailedExt( + &'static str, + #[error(source)] mullvad_management_interface::Status, + ), /// The given command is not correct in some way #[error(display = "Invalid command: {}", _0)] @@ -44,7 +50,20 @@ async fn main() { let exit_code = match run().await { Ok(_) => 0, Err(error) => { - eprintln!("{}", error.display_chain()); + match &error { + Error::RpcFailed(status) => { + eprintln!("{}: {:?}: {}", error, status.code(), status.message()) + } + Error::RpcFailedExt(_message, status) => { + eprintln!( + "{}\nCaused by: {:?}: {}", + error, + status.code(), + status.message() + ) + } + error => eprintln!("{}", error.display_chain()), + } 1 } }; diff --git a/mullvad-cli/src/state.rs b/mullvad-cli/src/state.rs index 9890218545..4cf826214f 100644 --- a/mullvad-cli/src/state.rs +++ b/mullvad-cli/src/state.rs @@ -23,7 +23,7 @@ pub fn state_listen(mut rpc: ManagementServiceClient) -> Receiver<Result<TunnelS _ => continue, }, Ok(None) => break, - Err(status) => Err(Error::GrpcClientError(status)), + Err(status) => Err(Error::RpcFailed(status)), }; if let Err(_) = sender.send(forward).await { @@ -32,7 +32,7 @@ pub fn state_listen(mut rpc: ManagementServiceClient) -> Receiver<Result<TunnelS } } Err(status) => { - let _ = sender.send(Err(Error::GrpcClientError(status))).await; + let _ = sender.send(Err(Error::RpcFailed(status))).await; } } }); |
