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

Return Errors instead of Panicing #30

Merged
merged 15 commits into from
Dec 11, 2019
Merged

Return Errors instead of Panicing #30

merged 15 commits into from
Dec 11, 2019

Conversation

tac0turtle
Copy link
Contributor

Return errors and have the application decide how they want to handle panicing :smile

Signed-off-by: Marko Baricevic [email protected]

- closes #28
- closes #4

Return errors and have the application decide how they want to handle panicing :smile

Signed-off-by: Marko Baricevic <[email protected]>
@tac0turtle tac0turtle added T:enhancement Type: Enhancement, New feature or request T:breaking Type: Breaking labels Nov 12, 2019
@tac0turtle tac0turtle self-assigned this Nov 12, 2019
@tac0turtle tac0turtle changed the title Return Errors instead of Panicing [WIP]: Return Errors instead of Panicing Nov 12, 2019
backend_test.go Show resolved Hide resolved
prefix_db.go Outdated Show resolved Hide resolved
prefix_db.go Outdated Show resolved Hide resolved
prefix_db.go Outdated Show resolved Hide resolved
@tac0turtle tac0turtle changed the title [WIP]: Return Errors instead of Panicing Return Errors instead of Panicing Nov 15, 2019
fsdb.go Show resolved Hide resolved
Copy link
Contributor

@alessio alessio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just left a comment. I like the gist of it, I just need a bit of more time to review it further

boltdb.go Show resolved Hide resolved
.gitignore Outdated Show resolved Hide resolved
c_level_db.go Outdated Show resolved Hide resolved
c_level_db.go Outdated Show resolved Hide resolved
go_level_db.go Outdated Show resolved Hide resolved
makefile Outdated Show resolved Hide resolved
prefix_db.go Show resolved Hide resolved
prefix_db.go Outdated Show resolved Hide resolved
prefix_db.go Outdated Show resolved Hide resolved
backend_test.go Show resolved Hide resolved
boltdb.go Outdated Show resolved Hide resolved
c_level_db.go Show resolved Hide resolved
go_level_db.go Outdated Show resolved Hide resolved
prefix_db.go Outdated Show resolved Hide resolved
prefix_db.go Outdated Show resolved Hide resolved
prefix_db.go Outdated Show resolved Hide resolved
rocks_db.go Outdated Show resolved Hide resolved
- add comment about why the error is ignored
- wraped a couple of errors with error.Wrap
@tac0turtle tac0turtle marked this pull request as ready for review December 5, 2019 11:56
types.go Show resolved Hide resolved
Copy link
Contributor

@alessio alessio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

Copy link

@alexanderbez alexanderbez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK

@@ -20,6 +20,8 @@ func TestBoltDBNewBoltDB(t *testing.T) {
db.Close()
}

//TODO: ADD TESTS!!!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this still a TODO?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, there is an issue for it. To keep the scope of this pr small I will handle it in subsequent PRs,

@krhubert
Copy link

krhubert commented Dec 9, 2019

LGTM - Great Job!

@tac0turtle tac0turtle requested a review from tessr December 9, 2019 11:43
@tac0turtle tac0turtle merged commit 3abb245 into master Dec 11, 2019
@tac0turtle tac0turtle deleted the marko/ErrorNoPanic branch December 11, 2019 12:27
func (itr *boltDBIterator) Next() {
itr.assertIsValid()
func (itr *boltDBIterator) Next() error {
if err := itr.assertIsValid(); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert should panic I believe

itr.assertIsValid()
return itr.source.Key()
func (itr cLevelDBIterator) Key() ([]byte, error) {
if err := itr.assertNoError(); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same. assertX should panic

// but this is being conveyed in the below if statement
key, _ := source.Key() //nolint:errcheck

if !source.Valid() || !bytes.HasPrefix(key, prefix) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the better way may be

pitr := &prefixIterator{
	prefix: prefix,
	start:  start,
	end:    end,
	source: source,
	valid:  false,
}

if !source.Valid() {
	return pitr
}
key, err := source.Key()
if err != nil {
	return nil, err
}
if !bytes.HasPrefix(key, prefix) {
	return pitr
}

@@ -329,7 +383,7 @@ func stripPrefix(key []byte, prefix []byte) (stripped []byte) {
panic("should not happen")
}
if !bytes.Equal(key[:len(prefix)], prefix) {
panic("should not happne")
panic("should not happn")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

happen

if !itr.valid {
panic("prefixIterator invalid, cannot call Key()")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

panic is appropriate here as it checks program logic (ie. nobody should call Key/Value if iterator is not Valid)

faddat pushed a commit to faddat/tm-db that referenced this pull request Feb 21, 2024
…endermint#30)

Bumps [golangci/golangci-lint-action](https://github.com/golangci/golangci-lint-action) from 3.3.1 to 3.4.0.
- [Release notes](https://github.com/golangci/golangci-lint-action/releases)
- [Commits](golangci/golangci-lint-action@v3.3.1...v3.4.0)

---
updated-dependencies:
- dependency-name: golangci/golangci-lint-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T:breaking Type: Breaking T:enhancement Type: Enhancement, New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Do not panic - return error instead Change DB interface to return errors
7 participants