Skip to content

Commit

Permalink
Merge branch 'master' into mdbx_devel
Browse files Browse the repository at this point in the history
  • Loading branch information
AskAlexSharov committed Sep 23, 2023
2 parents 6999ff9 + 7a11834 commit 0d46d64
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion mdbx/cursor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func TestCursor_Get_KV(t *testing.T) {
}

_, _, err = cur.Get([]byte("k0"), []byte("v0"), GetBothRange)
if !IsErrno(err, NotFound) {
if !IsNotFound(err) {
t.Errorf("unexpected error: %s", err)
}

Expand Down
20 changes: 11 additions & 9 deletions mdbx/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package mdbx
import "C"

import (
"fmt"
"os"
"syscall"
)
Expand All @@ -33,10 +34,10 @@ func (err *OpError) Error() string {
// Most often helper functions such as IsNotFound may be used instead of
// dealing with Errno values directly.
//
// lmdb.IsNotFound(err)
// lmdb.IsErrno(err, lmdb.TxnFull)
// lmdb.IsErrnoSys(err, syscall.EINVAL)
// lmdb.IsErrnoFn(err, os.IsPermission)
// lmdb.IsNotFound(err)
// lmdb.IsErrno(err, lmdb.TxnFull)
// lmdb.IsErrnoSys(err, syscall.EINVAL)
// lmdb.IsErrnoFn(err, os.IsPermission)
type Errno C.int

// The most common error codes do not need to be handled explicity. Errors can
Expand Down Expand Up @@ -76,6 +77,8 @@ const (
// other values may still be produced.
const minErrno, maxErrno C.int = C.MDBX_KEYEXIST, C.MDBX_LAST_ADDED_ERRCODE

var ErrNotFound = fmt.Errorf("key not found")

// App can re-define this messages from init() func
var CorruptErrorHardwareRecommendations = "Maybe free space is over on disk. Otherwise it's hardware failure. Before creating issue please use tools like https://www.memtest86.com to test RAM and tools like https://www.smartmontools.org to test Disk. To handle hardware risks: use ECC RAM, use RAID of disks, run multiple application instances (or do backups). If hardware checks passed - check FS settings - 'fsync' and 'flock' must be enabled. "
var CorruptErrorBacktraceRecommendations = "Otherwise - please create issue in Application repo." // with backtrace or coredump. To create coredump set compile option 'MDBX_FORCE_ASSERTIONS=1' and env variable 'GOTRACEBACK=crash'."
Expand All @@ -84,8 +87,9 @@ var CorruptErrorMessage = CorruptErrorHardwareRecommendations + " " + CorruptErr

func (e Errno) Error() string {
if e == Corrupted {
return "MDBX_CORRUPTED: " + CorruptErrorMessage
} else if e == Panic {
return "MDBX_FATAL: " + CorruptErrorMessage
}
if e == Panic {
return "MDBX_PANIC: " + CorruptErrorMessage
}
return C.GoString(C.mdbx_strerror(C.int(e)))
Expand All @@ -99,9 +103,7 @@ func _operrno(op string, ret int) error {
// IsNotFound returns true if the key requested in Txn.Get or Cursor.Get does
// not exist or if the Cursor reached the end of the database without locating
// a value (EOF).
func IsNotFound(err error) bool {
return IsErrno(err, NotFound)
}
func IsNotFound(err error) bool { return err == ErrNotFound } //nolint

func IsKeyExists(err error) bool {
return IsErrno(err, KeyExist)
Expand Down
3 changes: 3 additions & 0 deletions mdbx/error_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ func operrno(op string, ret C.int) error {
if ret == C.MDBX_SUCCESS || ret == C.MDBX_RESULT_TRUE {
return nil
}
if ret == C.MDBX_NOTFOUND {
return ErrNotFound
}
if minErrno <= ret && ret <= maxErrno {
return &OpError{Op: op, Errno: Errno(ret)}
}
Expand Down
3 changes: 3 additions & 0 deletions mdbx/error_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ func operrno(op string, ret C.int) error {
if ret == C.MDBX_SUCCESS || ret == C.MDBX_RESULT_TRUE {
return nil
}
if ret == C.MDBX_NOTFOUND {
return ErrNotFound
}
if minErrno <= ret && ret <= maxErrno {
return &OpError{Op: op, Errno: Errno(ret)}
}
Expand Down
2 changes: 1 addition & 1 deletion mdbx/txn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ func TestTxn_OpenDBI_emptyName(t *testing.T) {
_, err = txn.OpenDBISimple("", 0)
return err
})
if !IsErrno(err, NotFound) {
if !IsNotFound(err) {
t.Errorf("mdb_dbi_open: %v", err)
}

Expand Down

0 comments on commit 0d46d64

Please sign in to comment.