You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
disclaimer: The "No way" in the issue title is how it seems to me, but I'd be delighted to be proven wrong!
Actual behavior
In my CLI app I have error reporting that logs a given error + its chain of sources via the format specifier {}. My reporting prints:
error: error sending request for url (https://api.dpm.sh/sources): error trying to connect: dns error: failed to lookup address information: nodename nor servname provided, or not known
...because: error trying to connect: dns error: failed to lookup address information: nodename nor servname provided, or not known
...because: dns error: failed to lookup address information: nodename nor servname provided, or not known
...because: failed to lookup address information: nodename nor servname provided, or not known
My understanding is that I'm using core::error::Error in the way it's intended. As a result, I was confused why there was such redundancy at the various levels.
Expected behavior
My reporting would ideally print:
error: error sending request for url (https://api.dpm.sh/sources)
...because: error trying to connect
...because: dns error
...because: failed to lookup address information: nodename nor servname provided, or not known
Cause
I've gathered that the cause of the duplication is twofold:
I understand this is for the benefit of people who are simply logging a reqwest::Error via {}. What's less clear to me is how an app can control the reporting of the error chain without introducing redundancy.
Possible solutions
Is there any change that could be made to reqwest::Error such that the reporting scheme described above would produce the desired output? Some ideas:
Change the Display impls of both reqwest::Error and hyper::Error to be: {} describes only the root error, {:#} describes the entire chain. This is what anyhow::Error does. There may be merit to three widely-adopted crates behaving consistently with one another.
Add an alternate mode of formatting to reqwest::Error, {:#}, which would produce the desired output.
Add a method to reqwest::Error which returns something akin to a std::path::Display: an opaque struct with an alternate Display impl that produces the desired output.
disclaimer: The "No way" in the issue title is how it seems to me, but I'd be delighted to be proven wrong!
Actual behavior
In my CLI app I have error reporting that logs a given error + its chain of sources via the format specifier
{}
. My reporting prints:My understanding is that I'm using
core::error::Error
in the way it's intended. As a result, I was confused why there was such redundancy at the various levels.Expected behavior
My reporting would ideally print:
Cause
I've gathered that the cause of the duplication is twofold:
{}
formatting ofreqwest::Error
contains the{}
formatting of itssource
: https://github.com/seanmonstar/reqwest/blob/v0.11.18/src/error.rs#L204-L206reqwest::Error
is ahyper::Error
, whoseDisplay
impl does similarly:hyper::Error
prints its first cause in its Display impl, causes duplicate printing in many scenarios hyperium/hyper#2771I understand this is for the benefit of people who are simply logging a
reqwest::Error
via{}
. What's less clear to me is how an app can control the reporting of the error chain without introducing redundancy.Possible solutions
Is there any change that could be made to
reqwest::Error
such that the reporting scheme described above would produce the desired output? Some ideas:Display
impls of bothreqwest::Error
andhyper::Error
to be:{}
describes only the root error,{:#}
describes the entire chain. This is whatanyhow::Error
does. There may be merit to three widely-adopted crates behaving consistently with one another.reqwest::Error
,{:#}
, which would produce the desired output.reqwest::Error
which returns something akin to astd::path::Display
: an opaque struct with an alternateDisplay
impl that produces the desired output.hyper::Error
prints its first cause in its Display impl, causes duplicate printing in many scenarios hyperium/hyper#2771 (comment). Maybe a similar workaround is possible here, where a dependent of reqwest could define a type that wraps areqwest::Error
and whoseDisplay
impl downcasts things and does alternate formatting of error types that are known to include their source'sDisplay
in their ownDisplay
.Are there other options? And would the maintainers be open to merging a PR that implemented any of the above?
The text was updated successfully, but these errors were encountered: