-
Notifications
You must be signed in to change notification settings - Fork 282
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
Being able to choose the error type in tower-test #393
Comments
I think we'd be open to it, Im not quite sure yet what the implications of it are. What is your use case where downcasting doesn't work? |
I had a case which was something like: struct Worker<S> {
service: S
}
impl<S> Worker<S>
where
S: Service<Request, Response = Response>,
S::Error: std::error::Error + Send + Sync + 'static,
{
async fn do_some_work(&mut self) -> anyhow::Result<String> {
// ...poll_ready on inner service
let result = self.service
.call(make_request())
.await
.with_context(|| "Oh no")?; // from `anyhow::Context`, wraps an `Error`
// do something with result
Ok(...)
}
} and wanted to test the logic inside However, since But now that I think about it, I could just have a fixed error type in my test and wrap the I'm mostly thinking that in application-level tests, it would be convenient to have some way to just use a |
You should be able to change |
I think that would solve the use of Although looking at the code, I realized the use of |
Yeah, that makes sense, we probably want to revisit |
For anyone stumbling up on this issue, just searching for a way to get something which implements let (service, mut handle) = mock::spawn();
let mut service = service.map_result(|res| res.map_err(Arc::<dyn Error + Send + Sync>::from)); Since rust 1.52.0 Cheers |
Just found the let (service, mut handle) = mock::spawn();
let mut service = service.map_err(Arc::<dyn Error + Send + Sync>::from); Pretty sweet |
Stumbled on this, It would be nice for Error to be a generic. I would also be fine with panicking in case of Closed error. |
Yeah, feel free to open a PR, not sure how big the refactor is gonna be tho. |
Currently in
tower-test
, theMock
service's error type is fixed toBox<dyn Error + Send + Sync>
.I guess it's possible to work around it at the moment by creating a wrapper
Service
that does boxing/downcasting of errors, but are you open to the idea of having the error type be configurable? (it could even be a type param that defaults toBox<dyn Error + Send + Sync>
if unspecified)The text was updated successfully, but these errors were encountered: