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

feat: properly encapsulate quick_protobuf::Error #3894

Merged
merged 6 commits into from
May 12, 2023

Conversation

thomaseizinger
Copy link
Contributor

@thomaseizinger thomaseizinger commented May 8, 2023

Description

I noticed that we also still leak that dependency in several crates by providing a From impl so I've removed that one as well.

Resolves #3534.

Notes & open questions

Change checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • A changelog entry has been made in the appropriate crates

Comment on lines -133 to +132
pub struct DecodeError(String);

impl From<quick_protobuf::Error> for DecodeError {
fn from(e: quick_protobuf::Error) -> Self {
Self(e.to_string())
}
}

impl fmt::Display for DecodeError {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0)
}
}
#[error(transparent)]
pub struct DecodeError(quick_protobuf::Error);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am confused. Isn't the constructor of DecodeError the same as a From<quick_protobuf::Error>? Asked in a different way, changing DecodeError(quic_protobuf::Error) to e.g. DecodeError(SomeNewType) a breaking change? (Where SomeNewType might as well be quic_protobuf just as a new version.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, if the field is crate-private, you can't construct it from outside this crate. Trait impls are global and because From can be imported and used by anyone, anyone can call this implemented and thus depend on the underlying quick_protobuf version.

It is a very nasty situation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. Thanks for explaining!

@mergify mergify bot merged commit 1bf6264 into master May 12, 2023
@mergify mergify bot deleted the wrap-quick-protobuf-error branch May 12, 2023 02:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrap quick-protobuf::Error
2 participants