tonic
tonic copied to clipboard
pub constructor for tonic::transport::Error
Feature Request
Motivation
We have code that calls Endpoint::connect()
and handles the returned error. We want to write unit tests that exercise our error handling logic. Currently, we cannot create a tonic::transport::Error
because all of the constructor methods are pub(crate)
, and so we can't test our error handling logic.
We have a workaround, where we create a thin wrapper around Endpoint::connect()
that returns an Err variant like this:
enum TonicErrorWrapper {
Real(tonic::transport::Error),
Fake,
}
...and we only test with TonicErrorWrapper::Fake
. We would like if tonic::transport::Error
had a public constructor so we can test our error branches without introducing wrapper types.
Proposal
Make Error::new()
or Error::from_source()
public, instead of pub(crate)
. Or introduce some new constructors intended for public use.
I would even be fine with Error::dummy_instance_for_tests()
. I just need an actual instance for my tests.
I am not sure what would be best for public API surface of this crate. I'll leave that up to hyper team.