Skip to content

hyper::Error should either print source in display xor return a Some from Error::cause(), not both #2732

@nagisa

Description

@nagisa

Version
f1b89c1

Platform
Any

Description
Today the std::fmt::Display impl for hyper::Error has the following snippet:

hyper/src/error.rs

Lines 500 to 501 in f1b89c1

if let Some(ref cause) = self.inner.cause {
write!(f, "{}: {}", self.description(), cause)

and the std::error::Error::source impl for hyper::Error reads as such:

hyper/src/error.rs

Lines 510 to 513 in f1b89c1

self.inner
.cause
.as_ref()
.map(|cause| &**cause as &(dyn StdError + 'static))

This is somewhat problematic for code that properly prints out the error causation chain. e.g. I have seen an error like this:

error: error trying to connect: tcp connect error: Connection refused (os error 111)
caused by: tcp connect error: Connection refused (os error 111)
caused by: Connection refused (os error 111)

this is pretty unreadable. Now one might argue that hyper::Error::description() serves this use-case, and while that's true, it seems pretty awkward to pull in hyper into the code that's implements error presentation layer just to downcast and check for hyper.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-errorArea: error handlingB-rfcBlocked: More comments would be useful in determine next steps.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions