-
Notifications
You must be signed in to change notification settings - Fork 982
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
*: Don't leak prost
dependency in error types
#3058
Conversation
With the current design, a major version bump of `prost` leaks into all consumers of `prost-codec`.
This is an anti-pattern that will likely lead to duplicated error messages in logs.
8e8cd56
to
f41a15b
Compare
f41a15b
to
44fce3f
Compare
prost
dependency in error typesprost
dependency in error types
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Thanks for the many simplifications, e.g. using prost-codec. Thanks for the patch-by-patch pull request.
While this change improved the code in many places, I wonder about the definition of “breaking change”: is it not the case that wrapping |
It depends on what we consider the public API to be. In my view, handing an opaque error type to someone should communicate that "this is all you are gonna get". If I wanted to commit to a more specific API, I would have used an error enum with concrete variants. Depending on the Do you have a particular case at hand where changing our protobuf implementation (with this patch in place) breaks things for you? |
This is a reasonable stance, but it makes it impossible to selectively recover from those hidden error causes without risking runtime breakage. I don’t have an example with In this (PR) case I think it makes sense to hide the detailed cause. After your above explanation my only remaining point is that this obfuscation should in general be a conscious and justified decision — not “leaking a dependency” is not strong enough for my taste (the error type could just be re-exported). Not leaking an aspect of the build setup is stronger. |
The motivation here is that we want to move away from
For what it is worth, I share this view. |
Yes, we are in agreement. |
With the current design, a major version bump of `prost` leaks into all consumers of `prost-codec`.
Description
Whilst reviewing #3050, we discovered that we are currently leaking the
prost
dependency through our error types in various places. This would make https://github.com/libp2p/rust-libp2p/pull/3050/files a breaking change despite being entirely an implementation detail about our build(!) setup.This PR aims to resolve that hiding the concrete error in the variants with a newtype error that forwards
source
andDisplay
to its inner type. This preserves theDisplay
chain when using wrappers likeanyhow
.Patch-by-patch review is recommended.
Links to any relevant issues
Open Questions
Change checklist
I have added tests that prove my fix is effective or that my feature works