Skip to content

Commit 8a006c7

Browse files
committed
cli: improve dbus error messaging on linux
Fixes microsoft/vscode-remote-release#7778
1 parent 95e90d2 commit 8a006c7

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

cli/src/tunnels/service_linux.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::{
1717
constants::{APPLICATION_NAME, PRODUCT_NAME_LONG},
1818
log,
1919
state::LauncherPaths,
20-
util::errors::{wrap, AnyError},
20+
util::errors::{wrap, AnyError, DbusConnectFailedError},
2121
};
2222

2323
use super::ServiceManager;
@@ -40,7 +40,7 @@ impl SystemdService {
4040
async fn connect() -> Result<Connection, AnyError> {
4141
let connection = Connection::session()
4242
.await
43-
.map_err(|e| wrap(e, "Error creating dbus session. This command uses systemd for managing services, you should check that systemd is installed and running as a user. If it's already installed, you may need to:\n\n- Install the `dbus-user-session` package and reboot\n- Start the user dbus session with `systemctl --user enable dbus --now`. \n\nThe error encountered was"))?;
43+
.map_err(|e| DbusConnectFailedError(e.to_string()))?;
4444
Ok(connection)
4545
}
4646

@@ -110,6 +110,10 @@ impl ServiceManager for SystemdService {
110110

111111
info!(self.log, "Tunnel service successfully started");
112112

113+
if std::env::var("SSH_CLIENT").is_ok() || std::env::var("SSH_TTY").is_ok() {
114+
info!(self.log, "Tip: run `sudo loginctl enable-linger $USER` to ensure the service stays running after you disconnect.");
115+
}
116+
113117
Ok(())
114118
}
115119

cli/src/util/errors.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,26 @@ macro_rules! makeAnyError {
442442
};
443443
}
444444

445+
#[derive(Debug)]
446+
pub struct DbusConnectFailedError(pub String);
447+
448+
impl Display for DbusConnectFailedError {
449+
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
450+
let mut str = String::new();
451+
str.push_str("Error creating dbus session. This command uses systemd for managing services, you should check that systemd is installed and under your user.");
452+
453+
if std::env::var("WSL_DISTRO_NAME").is_ok() {
454+
str.push_str("\n\nTo enable systemd on WSL, check out: https://devblogs.microsoft.com/commandline/systemd-support-is-now-available-in-wsl/.\n\n");
455+
}
456+
457+
str.push_str("If running `systemctl status` works, systemd is ok, but your session dbus may not be. You might need to:\n\n- Install the `dbus-user-session` package, and reboot if it was not installed\n- Start the user dbus session with `systemctl --user enable dbus --now`.\n\nThe error encountered was: ");
458+
str.push_str(&self.0);
459+
str.push('\n');
460+
461+
write!(f, "{}", str)
462+
}
463+
}
464+
445465
/// Internal errors in the VS Code CLI.
446466
/// Note: other error should be migrated to this type gradually
447467
#[derive(Error, Debug)]
@@ -522,7 +542,8 @@ makeAnyError!(
522542
MissingHomeDirectory,
523543
OAuthError,
524544
InvalidRpcDataError,
525-
CodeError
545+
CodeError,
546+
DbusConnectFailedError
526547
);
527548

528549
impl From<reqwest::Error> for AnyError {

0 commit comments

Comments
 (0)