Skip to content

Commit 78293ec

Browse files
committed
Manually print error chain
reqwest#2199[0] removed the error source from its Display impl, causing us to lose context on why a request failed. Manually iterate over error sources and append them to output message to restore the original behavior. The first source is the intial error that we have wrapped, so that must be skipped in order to prevent duplicating the message. [0] seanmonstar/reqwest#2199
1 parent 2b6b385 commit 78293ec

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

cli/src/cmd_auth.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
// Copyright 2024 Oxide Computer Company
66

7+
use std::error::Error;
78
use std::fs::{File, OpenOptions};
89
use std::io::{self, Write};
910
use std::path::Path;
@@ -512,7 +513,20 @@ impl CmdAuthStatus {
512513
fn error_msg(e: &oxide::Error<oxide::types::Error>) -> String {
513514
match e {
514515
oxide::Error::ErrorResponse(ee) => format!("Error Response: {}", ee.message),
515-
ee => ee.to_string(),
516+
ee => {
517+
let mut err = ee.to_string();
518+
519+
// The immediate source of the error is already shown in the
520+
// Display impl. We need to skip the first source to avoid
521+
// duplicating it.
522+
let mut s = ee.source().and_then(|e| e.source());
523+
while let Some(source) = s {
524+
err += &format!(": {source}");
525+
s = source.source();
526+
}
527+
528+
err
529+
}
516530
}
517531
}
518532
}
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
Profile "jennifer" (<TEST-SERVER>) status: Authenticated
22
Profile "lightman" (<TEST-SERVER>) status: Authenticated
33
Profile "malvin" (<TEST-SERVER>) status: Error Response: ** IMPROPER REQUEST **
4-
Profile "sting" (https://unresolvabledomainnameihope) status: Communication Error: error sending request for url (https://unresolvabledomainnameihope/v1/me)
4+
Profile "sting" (https://unresolvabledomainnameihope) status: Communication Error: error sending request for url (https://unresolvabledomainnameihope/v1/me): client error (Connect):

0 commit comments

Comments
 (0)