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

Recover from panic in cosmos store #1257

Merged
merged 2 commits into from
Aug 24, 2019
Merged

Recover from panic in cosmos store #1257

merged 2 commits into from
Aug 24, 2019

Conversation

krhubert
Copy link
Contributor

No description provided.

@krhubert krhubert added the bug Something isn't working label Aug 23, 2019
@krhubert krhubert added this to the next milestone Aug 23, 2019
@krhubert krhubert self-assigned this Aug 23, 2019
}
}()
has = s.store.Has(key)
return
Copy link
Member

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

Copy link
Member

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.

Copy link
Member

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
}

Copy link
Contributor Author

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

@mesg-bot
Copy link
Member

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

@antho1404 antho1404 merged commit 35757e7 into dev Aug 24, 2019
@antho1404 antho1404 deleted the feature/cosmos-store branch August 24, 2019 12:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants