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

lmdbscan: Scanner.Scan panics if lmdbscan.New() failed. #21

Closed
bmatsuo opened this issue Nov 2, 2015 · 0 comments · Fixed by #22
Closed

lmdbscan: Scanner.Scan panics if lmdbscan.New() failed. #21

bmatsuo opened this issue Nov 2, 2015 · 0 comments · Fixed by #22
Milestone

Comments

@bmatsuo
Copy link
Owner

bmatsuo commented Nov 2, 2015

If lmdbscan.New() fails then the error will be wiped out when the scanner's Scan method will panic attempting to access the underlying cursor. This is counter to the goals of the lmdbscan package, where ideally errors are checked for once at the end of the transaction.

scanner.New(txn, 1234)
defer scanner.Close()
for scanner.Scan() { // panic!
  log.Printf("k=%q v=%q", scanner.Key(), scanner.Val())
}
return scanner.Err()
bmatsuo added a commit that referenced this issue Nov 2, 2015
Fixes #21

Method Scanner.Scan, checks the underlying cursor before calling
Cursor.Get.  This allows a Scanner.Err to catch an error opening the
cursor even if called at the end of the transaction.

If the Scanner.Scan method is called after the scanner has been closed
then a Scanner.Err is set to return an error indicating that the scanner
is closed.
@bmatsuo bmatsuo added this to the v1.3.0 milestone Nov 2, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant