-
Notifications
You must be signed in to change notification settings - Fork 137
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
Conversation
- 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]>
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.
Just left a comment. I like the gist of it, I just need a bit of more time to review it further
- add comment about why the error is ignored - wraped a couple of errors with error.Wrap
17b62f1
to
c72ac02
Compare
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.
Looks good
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.
ACK
@@ -20,6 +20,8 @@ func TestBoltDBNewBoltDB(t *testing.T) { | |||
db.Close() | |||
} | |||
|
|||
//TODO: ADD TESTS!!! |
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.
Is this still a TODO?
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.
yes, there is an issue for it. To keep the scope of this pr small I will handle it in subsequent PRs,
LGTM - Great Job! |
func (itr *boltDBIterator) Next() { | ||
itr.assertIsValid() | ||
func (itr *boltDBIterator) Next() error { | ||
if err := itr.assertIsValid(); err != nil { |
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.
assert should panic I believe
itr.assertIsValid() | ||
return itr.source.Key() | ||
func (itr cLevelDBIterator) Key() ([]byte, error) { | ||
if err := itr.assertNoError(); err != nil { |
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.
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) { |
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.
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") |
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.
happen
if !itr.valid { | ||
panic("prefixIterator invalid, cannot call Key()") |
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.
panic is appropriate here as it checks program logic (ie. nobody should call Key/Value if iterator is not Valid)
…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>
Return errors and have the application decide how they want to handle panicing :smile
Signed-off-by: Marko Baricevic [email protected]