-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
feat(client): TrySendError<T>
is From<Error>
#3883
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
base: master
Are you sure you want to change the base?
feat(client): TrySendError<T>
is From<Error>
#3883
Conversation
this commit introduces a new trait implementation for `hyper::client::conn::TrySendError<T>`. this commit allows a `TrySendError<T>` to be constructed `From` a conventional `hyper::Error`. one example of a motivating use case for this change is that this is needed in order to use interfaces like `hyper::client::conn::http2::SendRequest::try_send_request()` or `hyper::client::conn::http1::SendRequest::try_send_request()` in the context of tower middleware; the `Service<T>` trait's signature is such that the same error type be returned from `Service::poll_ready()` and `Service::call()`. thus, the `?` operator may construct a `TrySendError<T>` from errors possibly returned by `hyper::client::conn::http2::SendRequest::poll_ready()` or `hyper::client::conn::http1::SendRequest::poll_ready()`, within a `Service<T>` that eventually calls `try_send_request()` in the context of `Service::call()`. --- see: * hyperium#3691 * https://docs.rs/hyper/latest/hyper/client/conn/struct.TrySendError.html * https://docs.rs/hyper/latest/hyper/struct.Error.html * https://docs.rs/hyper/latest/hyper/client/conn/http2/struct.SendRequest.html#method.try_send_request * https://docs.rs/tower/latest/tower/trait.Service.html#associatedtype.Error * https://docs.rs/hyper/latest/hyper/client/conn/http1/struct.SendRequest.html#method.poll_ready * https://docs.rs/hyper/latest/hyper/client/conn/http2/struct.SendRequest.html#method.poll_ready Signed-off-by: katelyn martin <[email protected]>
e78bc83
to
0edd1c8
Compare
This one I'm slightly skeptical about. I've generally adopt the opinion of making errors not constructable outside of the conditions that they represent. (I know some people want to construct them during tests, but I find it extremely valuable to reason about the guarantee of an error because of a certain call.) Is it possible to solve this locally in the service impl? Either by cast them into a |
definitely, i am sympathetic to your point! i think there are some other ways on services, and error handling
unfortunately, this isn't ideally handled locally in the tower calls these higher-order services a very similar to this general pattern is the connection-oriented hyper, circa 0.14, relied on vendored variation(s) of this. https://github.com/hyperium/hyper/blob/0.14.x/src/service/make.rs#L11-L20 https://github.com/hyperium/hyper/blob/0.14.x/src/client/connect/mod.rs#L438-L455 while now for the purposes of this discussion, all of this is relevant because it means within such an architecture, a other options
|
this commit introduces a new trait implementation for
hyper::client::conn::TrySendError<T>
.this commit allows a
TrySendError<T>
to be constructedFrom
a conventionalhyper::Error
.one example of a motivating use case for this change is that this is needed in order to use interfaces like
hyper::client::conn::http2::SendRequest::try_send_request()
orhyper::client::conn::http1::SendRequest::try_send_request()
in the context of tower middleware; theService<T>
trait's signature is such that the same error type be returned fromService::poll_ready()
andService::call()
.thus, the
?
operator can construct aTrySendError<T>
from errors possibly returned byhyper::client::conn::http2::SendRequest::poll_ready()
orhyper::client::conn::http1::SendRequest::poll_ready()
, within aService<T>
that eventually callstry_send_request()
in the context ofService::call()
.see:
SendRequest::try_send_request()
method #3691