Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide introspection on hyper::Error #1542

Closed
jonhoo opened this issue Jun 5, 2018 · 4 comments
Closed

Provide introspection on hyper::Error #1542

jonhoo opened this issue Jun 5, 2018 · 4 comments
Labels
A-error Area: error handling B-rfc Blocked: More comments would be useful in determine next steps.

Comments

@jonhoo
Copy link
Contributor

jonhoo commented Jun 5, 2018

I have an application in which I want to try to set up a server on a specific port, but if that port is taken (i.e., an AddrInUse error is raised), it should fall back to any port (i.e., port 0). Unfortunately, since hyper's error type is now opaque (as of 5d3c472), I can no longer easily see if that was the cause of an error raised by Server::try_bind.

While I could construct a TcpListener myself and then pass that listener's Incoming to Server::builder, that's an unfortunate amount of extra boilerplate. Perhaps it would make sense to expose an as_io_error(&self) -> Option<&io::Error> on hyper::Error?

@seanmonstar
Copy link
Member

I saw mention of this in IRC, it seems you can't downcast the cause because Error::cause() doesn't return a Error + 'static, right?

What if hyper::Error were to get a cause_static (sorry, naming is hard) method, kind of like std::io::Error::get_ref, to allow downcasting?

@seanmonstar seanmonstar added B-rfc Blocked: More comments would be useful in determine next steps. A-error Area: error handling labels Jun 5, 2018
@jonhoo
Copy link
Contributor Author

jonhoo commented Jun 5, 2018

That'd be nice, but is there a particular reason you don't want to expose the io::Error through an explicit as_io_error method? As someone pointed out on IRC when I asked about it, cause() isn't really intended to be used as a way to figure out if a particular error occurred. Part of this is because causes form a chain, and you don't technically know how deep you have to go. And more importantly, the error nesting could change between versions.

@seanmonstar
Copy link
Member

I'm not especially against some form of as_io_error, I was just thinking that people may wish to access the errors they created themselves, like from a Payload or Service, and suggested something that might solve all cases.

@jonhoo
Copy link
Contributor Author

jonhoo commented Jun 6, 2018

Oh, yeah, I think having both is probably a good idea! I think my concern about cause nesting would make it pretty difficult to extract user errors from behind a hyper::Error nonetheless, but at least it would be possible!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-error Area: error handling B-rfc Blocked: More comments would be useful in determine next steps.
Projects
None yet
Development

No branches or pull requests

2 participants