diff options
| author | David Lönnhager <david.l@mullvad.net> | 2023-06-08 11:00:07 +0200 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2023-06-08 11:00:07 +0200 |
| commit | 05c8a1f8fa425dbc0a144892ddc869fbe45cc48b (patch) | |
| tree | 9f712f14a461ab149e08352b0090419d6bb26965 | |
| parent | 67b7f7d987898df0dce5d78887ecf6f9c8776143 (diff) | |
| parent | 7a155092662260116c5d7829645e7dfeaf7a0665 (diff) | |
| download | mullvadvpn-05c8a1f8fa425dbc0a144892ddc869fbe45cc48b.tar.xz mullvadvpn-05c8a1f8fa425dbc0a144892ddc869fbe45cc48b.zip | |
Merge branch 'improve-error-handling-in-connect-and-status-commands-des-110'
| -rw-r--r-- | mullvad-cli/src/cmds/status.rs | 20 | ||||
| -rw-r--r-- | mullvad-cli/src/cmds/tunnel_state.rs | 31 |
2 files changed, 50 insertions, 1 deletions
diff --git a/mullvad-cli/src/cmds/status.rs b/mullvad-cli/src/cmds/status.rs index 8ddd195333..a4a8add15e 100644 --- a/mullvad-cli/src/cmds/status.rs +++ b/mullvad-cli/src/cmds/status.rs @@ -2,7 +2,7 @@ use anyhow::Result; use clap::{Args, Subcommand}; use futures::StreamExt; use mullvad_management_interface::{client::DaemonEvent, MullvadProxyClient}; -use mullvad_types::states::TunnelState; +use mullvad_types::{device::DeviceState, states::TunnelState}; use crate::format; @@ -81,6 +81,9 @@ impl Status { pub async fn handle(cmd: Option<Status>, args: StatusArgs) -> Result<()> { let mut rpc = MullvadProxyClient::new().await?; let state = rpc.get_tunnel_state().await?; + let device = rpc.get_device().await?; + + print_account_loggedout(&state, &device); if args.debug { println!("Tunnel state: {state:#?}"); @@ -122,3 +125,18 @@ async fn print_location(rpc: &mut MullvadProxyClient) -> Result<()> { ); Ok(()) } + +fn print_account_loggedout(state: &TunnelState, device: &DeviceState) { + match state { + TunnelState::Connecting { .. } | TunnelState::Connected { .. } | TunnelState::Error(_) => { + match device { + DeviceState::LoggedOut => { + println!("Warning: You are not logged in to an account.") + } + DeviceState::Revoked => println!("Warning: This device has been revoked."), + DeviceState::LoggedIn(_) => (), + } + } + TunnelState::Disconnected | TunnelState::Disconnecting(_) => (), + } +} diff --git a/mullvad-cli/src/cmds/tunnel_state.rs b/mullvad-cli/src/cmds/tunnel_state.rs index 383b343ef4..6e115c5ba1 100644 --- a/mullvad-cli/src/cmds/tunnel_state.rs +++ b/mullvad-cli/src/cmds/tunnel_state.rs @@ -2,11 +2,15 @@ use crate::format; use anyhow::{anyhow, Result}; use futures::{Stream, StreamExt}; use mullvad_management_interface::{client::DaemonEvent, MullvadProxyClient}; +use mullvad_types::device::DeviceState; use mullvad_types::states::TunnelState; pub async fn connect(wait: bool) -> Result<()> { let mut rpc = MullvadProxyClient::new().await?; + let device_state = rpc.get_device().await?; + print_account_loggedout(&device_state); + let listener = if wait { Some(rpc.events_listen().await?) } else { @@ -48,6 +52,9 @@ pub async fn disconnect(wait: bool) -> Result<()> { pub async fn reconnect(wait: bool) -> Result<()> { let mut rpc = MullvadProxyClient::new().await?; + let device_state = rpc.get_device().await?; + print_account_loggedout(&device_state); + let listener = if wait { Some(rpc.events_listen().await?) } else { @@ -83,3 +90,27 @@ async fn wait_for_tunnel_state( } Err(anyhow!("Failed to wait for expected tunnel state")) } + +/// Checks the if the user is logged in. If not, we print a warning to get their +/// attention. +/// +/// When using the CLI, the user could potentially end up in a situation where +/// they try to connect to a Mullvad relay without having successfully logged in +/// to their account. In this case, we at least want to issue a warning to guide +/// the user when they inevitably will go troubleshooting. +fn print_account_loggedout(state: &DeviceState) { + match state { + DeviceState::LoggedOut => println!("Warning: You are not logged in to an account."), + DeviceState::Revoked => println!("Warning: This device has been revoked"), + DeviceState::LoggedIn(_) => return, // Normal case, do nothing. + }; + + println!( + "Mullvad is blocking all network traffic until you perform one of the following actions: + +1. Login to a Mullvad account with available time/credits. +2. Disconnect from Mullvad VPN. This can either be done from the CLI or the Mullvad App. + +For more information, try 'mullvad account -h' or 'mullvad disconnect -h'" + ); +} |
