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

modules: Change *Reader traits to return Result instead of Option #73

Closed
5 tasks done
yito88 opened this issue Aug 9, 2021 · 4 comments
Closed
5 tasks done

modules: Change *Reader traits to return Result instead of Option #73

yito88 opened this issue Aug 9, 2021 · 4 comments
Assignees
Labels
A: good-first-issue Admin: good for newcomers

Comments

@yito88
Copy link
Contributor

yito88 commented Aug 9, 2021

Crate

ibc

Summary

The functions of the module readers in contexts (e.g. ClientReader) can return Result instead of Option.

Problem Definition

Most of the readers get a module or state from the storage. These operations could fail, e.g. DB failure. A reader function returns just None in this case for now. It looks difficult to handle the failure.

For example, when initializing a connection, ClientReader returns None due to a temporary DB error. It can be done by just retrying the initialization. If the reader returns None because the corresponding client state doesn't exist, we need to create a client at first. If Result returns, we can handle the failure more clearly.

Proposal

The functions of the module readers return Result instead of Option

Acceptance Criteria

Readers returns Result


For Admin Use

  • Not duplicate issue
  • Appropriate labels applied
  • Appropriate milestone (priority) applied
  • Appropriate contributors tagged
  • Contributor assigned/self-assigned
@yito88
Copy link
Contributor Author

yito88 commented Aug 9, 2021

I think we need discussion because this proposal affects many IBC handlers. What do you think?

@adizere
Copy link
Contributor

adizere commented Aug 10, 2021

Your proposal is sound. Our current approach using return values consisting of an Option<..> was good enough so far, but it's probably overly simplistic in practice.

Would you like to take a stab at starting to implement the necessary modifications for a simple Context, e.g., ClientReader? Glad to help reviewing and merging that. This will probably require that we also define the specific kind of errors that this context can return (see here for an example of error definitions).

@yito88
Copy link
Contributor Author

yito88 commented Aug 17, 2021

This is a question. I'd like to know how to add errors for other failures to the error list.

I tried to add a read failure with std error. It looks wrong. I want to give any error to this error, e.g. my storage error. What should I do?

        ReadFailure
            [ std::error::Error ]
            | e | {
                format_args!("Reading an object failed with reason: {}", e.to_string())
            },

@romac
Copy link
Member

romac commented Aug 17, 2021

Try this:

        ReadFailure
            [ DisplayOnly<Box<dyn std::error::Error + Send + Sync>> ]
            | e | {
                format_args!("Reading an object failed, reason: {}", e)
            },

@romac romac changed the title Context reader returns Result Change ibc *Reader traits to return Result instead of Option Aug 24, 2021
@romac romac changed the title Change ibc *Reader traits to return Result instead of Option modules: Change *Reader traits to return Result instead of Option Aug 24, 2021
@hu55a1n1 hu55a1n1 transferred this issue from informalsystems/hermes Sep 29, 2022
shuoer86 pushed a commit to shuoer86/ibc-rs that referenced this issue Nov 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A: good-first-issue Admin: good for newcomers
Projects
None yet
Development

No branches or pull requests

4 participants