From b6e1385e39e3d454fbe16088207f5a027742a11b Mon Sep 17 00:00:00 2001 From: Fintan Halpenny Date: Fri, 16 Feb 2024 13:50:08 +0000 Subject: [PATCH] httpd: improve error message for missing browser If `open` or `xdg-open` fail the error is: No such file or directory (os error 2) This generally means that the command could not open the browser on the OS. To provide better help, improve the error message by informing the user what went wrong and that they can run `rad web --no-open` instead, while still printing the URL to visit. Signed-off-by: Fintan Halpenny X-Clacks-Overhead: GNU Terry Pratchett --- radicle-httpd/src/commands/web.rs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/radicle-httpd/src/commands/web.rs b/radicle-httpd/src/commands/web.rs index d14654de..c70c40c4 100644 --- a/radicle-httpd/src/commands/web.rs +++ b/radicle-httpd/src/commands/web.rs @@ -198,16 +198,22 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> { let cmd_name = "xdg-open"; let mut cmd = Command::new(cmd_name); - - match cmd.arg(auth_url.as_str()).spawn()?.wait() { - Ok(exit_status) => { - if exit_status.success() { - term::success!("Opened {auth_url}"); - } else { + match cmd.arg(auth_url.as_str()).spawn() { + Ok(mut child) => match child.wait() { + Ok(exit_status) => { + if exit_status.success() { + term::success!("Opened {auth_url}"); + } else { + term::info!("Visit {auth_url} to connect"); + } + } + Err(_) => { term::info!("Visit {auth_url} to connect"); } - } + }, Err(_) => { + term::error(format!("Could not open web browser via `{cmd_name}`")); + term::hint("Use `rad web --no-open` if this continues"); term::info!("Visit {auth_url} to connect"); } }