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

Update core store iterator API to return errors #14698

Closed
Tracked by #14683
aaronc opened this issue Jan 19, 2023 · 4 comments
Closed
Tracked by #14683

Update core store iterator API to return errors #14698

aaronc opened this issue Jan 19, 2023 · 4 comments
Assignees
Labels

Comments

@aaronc
Copy link
Member

aaronc commented Jan 19, 2023

In #14622, we added error return values to the cosmossdk.io/core/store.Store methods. In discussions in that PR, it was noted that the Iterator interface doesn't have error return values but rather an Error() method which isn't used correctly. As a follow-up, we would like to adapt the Iterator interface to return errors in appropriate places.

@tac0turtle
Copy link
Member

This should also be opened on cosmos-db. The interface is there. Should we do this as part of v1 on cosmos-db or v2?

@tac0turtle
Copy link
Member

this is something we should keep in mind for store v2 but no need to change the current design. With things like orm and collections teams wont really need to deal with this api directly

@github-project-automation github-project-automation bot moved this from 📝 Todo to 👏 Done in Cosmos-SDK Feb 23, 2023
@tac0turtle tac0turtle removed the Q1:2023 label Apr 3, 2023
@tac0turtle tac0turtle removed this from Cosmos-SDK May 31, 2023
@mhofman
Copy link

mhofman commented Jul 22, 2023

This issue has bitten me hard, I don't understand why it was closed.

Cosmos iterators borrow the tendermint iterator interface, which according to the documentation are supposed to be used with the following pattern:

var itr Iterator = ...
defer itr.Close()
for ; itr.Valid(); itr.Next() {
  k, v := itr.Key(); itr.Value()
  ...
}
if err := itr.Error(); err != nil {
  ...
}

However when you do so with most iterators returned by cosmos, err will not be nil for successful iterations that ran to completion. Error() is not supposed to be an "alias" for Valid().

With cosmos iterators there is currently no way to know if an iteration stopped because of an error or because it ran to completion.

@alexanderbez
Copy link
Contributor

Yikes, that seems like a pretty bad design flaw :/

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 a pull request may close this issue.

4 participants