Skip to content

Commit c926441

Browse files
authored
Print error source on failure in CLI (#740)
Currently the `oxide` binary will print the error returned when a subcommand fails, but not any `source` errors attached to it. In the context of connection failures from the `auth login` subcommand, the output was only `Request failed`, giving the user no context on why the failure occurred. If present, append the source of the error to the user-facing message. Previously: ``` $ oxide auth login --host oxide.invalid Request failed ``` Now: ``` $ oxide auth login --host oxide.invalid Request failed: error sending request for url \ (http://oxide.invalid/device/auth): error trying to connect: dns \ error: failed to lookup address information: nodename nor servname \ provided, or not known ```
1 parent e653541 commit c926441

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

cli/src/cmd_auth.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,27 @@ impl CmdAuthStatus {
486486

487487
#[cfg(test)]
488488
mod tests {
489+
#[test]
490+
fn test_cmd_auth_login() {
491+
use assert_cmd::Command;
492+
use predicates::str;
493+
494+
let bad_url = "sys.oxide.invalid";
495+
496+
// Validate connection error details are printed
497+
Command::cargo_bin("oxide")
498+
.unwrap()
499+
.arg("auth")
500+
.arg("login")
501+
.arg("--host")
502+
.arg(bad_url)
503+
.assert()
504+
.failure()
505+
.stderr(str::starts_with(format!(
506+
"Request failed: error sending request for url (https://{bad_url}/device/auth):"
507+
)));
508+
}
509+
489510
#[test]
490511
fn test_parse_host() {
491512
use super::parse_host;

cli/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ async fn main() {
101101
.await
102102
.unwrap();
103103
if let Err(e) = result {
104-
eprintln!("{e}");
104+
let src = e.source().map(|s| format!(": {s}")).unwrap_or_default();
105+
eprintln!("{e}{src}");
105106
std::process::exit(1)
106107
}
107108
}

0 commit comments

Comments
 (0)