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

Implement PartialEq for rpc::Error #1249

Open
apollo-sturdy opened this issue Dec 12, 2022 · 2 comments
Open

Implement PartialEq for rpc::Error #1249

apollo-sturdy opened this issue Dec 12, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@apollo-sturdy
Copy link

Description

I'm trying to use the Error type from tendermint_rpc in an error type of my own using thiserror and would like to derive PartialEq on my error type, but this is currently not possible since the tendermint_rpc Error does not implement PartialEq. It does have a derive attribute for PartialEq, but according to the doc comments in flex_error these are not added to the main error struct. So either flex_error needs to be updated to implement PartialEq for all error types created with the define_error! macro, or PartialEq needs to be specifically implemented for the tendermint_rpc Error.

Definition of "done"

PartialEq is implemented for rpc::Error.

@apollo-sturdy apollo-sturdy added the enhancement New feature or request label Dec 12, 2022
@romac
Copy link
Member

romac commented Dec 12, 2022

@soareschen Can you take a look at this please?

@soareschen
Copy link
Contributor

There are a few ways you can solve this:

  • Submit PR upstream to add the PartialEq instances to the error types in tendermint_rpc.
  • Manually implement PartialEq in your error type by inspecting into the error detail.
  • Use alternative approaches to check for error equality. The common use case of error equality is to check whether an error returned in tests is the same as expected. This can be done with a match on the error detail. The matching can be simplified with helper methods such as defined here.

Note that as errors can be wrapped in many ways, a simple equality check may sometimes not be sufficient to check on whether two errors are "equals". A simple way to think of it is that you could for example get an IoError from a network access or a file access. However the IoError may be wrapped in different sub-errors such as NetworkError or FileError. So you need to look at the error definitions to figure out whether there are multiple sources of the error of interest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants