-
Notifications
You must be signed in to change notification settings - Fork 13
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
Recover from panic in cosmos store #1257
Conversation
17bad6e
to
3dfd9bd
Compare
} | ||
}() | ||
has = s.store.Has(key) | ||
return |
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.
can we return explicitly the error here and avoid to have named outputs to be consistent with the rest of the codebase
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.
Unfortunately, that's not possible with the error recover system. The output have to be named in order to be "replaced" by the defer function.
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.
declaring an error variable at the beginning of the function wouldn't work?
func (s *CosmosStore) Has(key []byte) (bool, error) {
var err error
defer func() {
if r := recover(); r != nil {
var ok bool
if err, ok = r.(error); !ok {
err = fmt.Errorf("store: %s", r)
}
}
}()
return s.store.Has(key), err
}
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.
Nope, because defer is invoked
"after" retrun statment, not before :/
you can read about this in details here https://medium.com/@blanchon.vincent/go-how-does-defer-statement-work-1a9492689b6e
This pull request has been mentioned on MESG Community. There might be relevant details there: https://forum.mesg.com/t/network-implementation-with-cosmossdk/304/15 |
No description provided.