ethdb: rewrite leveldb/pebble/memorydb notfound to ethdb.notfound

Signed-off-by: jsvisa <delweng@gmail.com>
This commit is contained in:
jsvisa 2023-08-27 08:19:55 +08:00
parent 340b805fac
commit 108adb6a7a
3 changed files with 16 additions and 7 deletions

View file

@ -191,6 +191,9 @@ func (db *Database) Has(key []byte) (bool, error) {
func (db *Database) Get(key []byte) ([]byte, error) {
dat, err := db.db.Get(key, nil)
if err != nil {
if err == leveldb.ErrNotFound {
return nil, ethdb.ErrNotFound
}
return nil, err
}
return dat, nil
@ -469,7 +472,11 @@ func (snap *snapshot) Has(key []byte) (bool, error) {
// Get retrieves the given key if it's present in the snapshot backing by
// key-value data store.
func (snap *snapshot) Get(key []byte) ([]byte, error) {
return snap.db.Get(key, nil)
val, err := snap.db.Get(key, nil)
if err == leveldb.ErrNotFound {
return nil, ethdb.ErrNotFound
}
return val, err
}
// Release releases associated resources. Release should always succeed and can

View file

@ -32,10 +32,6 @@ var (
// invocation of a data access operation.
errMemorydbClosed = errors.New("database closed")
// errMemorydbNotFound is returned if a key is requested that is not found in
// the provided memory database.
errMemorydbNotFound = errors.New("not found")
// errSnapshotReleased is returned if callers want to retrieve data from a
// released snapshot.
errSnapshotReleased = errors.New("snapshot released")
@ -98,7 +94,7 @@ func (db *Database) Get(key []byte) ([]byte, error) {
if entry, ok := db.db[string(key)]; ok {
return common.CopyBytes(entry), nil
}
return nil, errMemorydbNotFound
return nil, ethdb.ErrNotFound
}
// Put inserts the given value into the key-value store.
@ -377,7 +373,7 @@ func (snap *snapshot) Get(key []byte) ([]byte, error) {
if entry, ok := snap.db[string(key)]; ok {
return common.CopyBytes(entry), nil
}
return nil, errMemorydbNotFound
return nil, ethdb.ErrNotFound
}
// Release releases associated resources. Release should always succeed and can

View file

@ -267,6 +267,9 @@ func (d *Database) Get(key []byte) ([]byte, error) {
}
dat, closer, err := d.db.Get(key)
if err != nil {
if err == pebble.ErrNotFound {
return nil, ethdb.ErrNotFound
}
return nil, err
}
ret := make([]byte, len(dat))
@ -350,6 +353,9 @@ func (snap *snapshot) Has(key []byte) (bool, error) {
func (snap *snapshot) Get(key []byte) ([]byte, error) {
dat, closer, err := snap.db.Get(key)
if err != nil {
if err == pebble.ErrNotFound {
return nil, ethdb.ErrNotFound
}
return nil, err
}
ret := make([]byte, len(dat))