diff --git a/storage/operation/reads.go b/storage/operation/reads.go index 1df0bdc85b4..6c14102bbc3 100644 --- a/storage/operation/reads.go +++ b/storage/operation/reads.go @@ -130,7 +130,7 @@ func TraverseByPrefix(r storage.Reader, prefix []byte, iterFunc IterationFunc, o // When this returned function is executed (and only then), it will write into the `keyExists` whether // the key exists. // No errors are expected during normal operation. -func KeyExists(r storage.Reader, key []byte) (exist bool, errExit error) { +func KeyExists(r storage.Reader, key []byte) (bool, error) { _, closer, err := r.Get(key) if err != nil { // the key does not exist in the database @@ -140,9 +140,7 @@ func KeyExists(r storage.Reader, key []byte) (exist bool, errExit error) { // exception while checking for the key return false, irrecoverable.NewExceptionf("could not load data: %w", err) } - defer func() { - errExit = closer.Close() - }() + defer closer.Close() // the key does exist in the database return true, nil @@ -155,15 +153,13 @@ func KeyExists(r storage.Reader, key []byte) (exist bool, errExit error) { // - storage.ErrNotFound if the key does not exist in the database // - generic error in case of unexpected failure from the database layer, or failure // to decode an existing database value -func RetrieveByKey(r storage.Reader, key []byte, entity interface{}) (errExit error) { +func RetrieveByKey(r storage.Reader, key []byte, entity interface{}) error { val, closer, err := r.Get(key) if err != nil { return err } - defer func() { - errExit = closer.Close() - }() + defer closer.Close() err = msgpack.Unmarshal(val, entity) if err != nil { @@ -176,7 +172,7 @@ func RetrieveByKey(r storage.Reader, key []byte, entity interface{}) (errExit er // keys with the format prefix` + `height` (where "+" denotes concatenation of binary strings). The height // is encoded as Big-Endian (entries with numerically smaller height have lexicographically smaller key). // The function finds the *highest* key with the given prefix and height equal to or below the given height. -func FindHighestAtOrBelowByPrefix(r storage.Reader, prefix []byte, height uint64, entity interface{}) (errExit error) { +func FindHighestAtOrBelowByPrefix(r storage.Reader, prefix []byte, height uint64, entity interface{}) error { if len(prefix) == 0 { return fmt.Errorf("prefix must not be empty") } @@ -186,9 +182,7 @@ func FindHighestAtOrBelowByPrefix(r storage.Reader, prefix []byte, height uint64 if err != nil { return fmt.Errorf("can not create iterator: %w", err) } - defer func() { - errExit = it.Close() - }() + defer it.Close() var highestKey []byte @@ -209,9 +203,7 @@ func FindHighestAtOrBelowByPrefix(r storage.Reader, prefix []byte, height uint64 return err } - defer func() { - errExit = closer.Close() - }() + defer closer.Close() err = msgpack.Unmarshal(val, entity) if err != nil {