Skip to content

Commit

Permalink
fix(code standards): use gerr err not found (dymensionxyz#878)
Browse files Browse the repository at this point in the history
  • Loading branch information
danwt authored May 22, 2024
1 parent a10ad36 commit 60e221f
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
4 changes: 3 additions & 1 deletion block/produce.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"fmt"
"time"

"github.com/dymensionxyz/dymint/gerr"

"github.com/dymensionxyz/dymint/store"

"github.com/dymensionxyz/dymint/types"
Expand Down Expand Up @@ -123,7 +125,7 @@ func (m *Manager) produceBlock(allowEmpty bool) (*types.Block, *types.Commit, er
return nil, nil, fmt.Errorf("load commit after load block: height: %d: %w: %w", newHeight, err, ErrNonRecoverable)
}
m.logger.Info("Using pending block.", "height", newHeight)
} else if !errors.Is(err, store.ErrKeyNotFound) {
} else if !errors.Is(err, gerr.ErrNotFound) {
return nil, nil, fmt.Errorf("load block: height: %d: %w: %w", newHeight, err, ErrNonRecoverable)
} else {
block = m.Executor.CreateBlock(newHeight, lastCommit, lastHeaderHash, m.State, m.Conf.BlockBatchMaxSizeBytes)
Expand Down
4 changes: 3 additions & 1 deletion indexers/blockindexer/kv/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"strconv"
"strings"

"github.com/dymensionxyz/dymint/gerr"

"github.com/google/orderedcode"

abci "github.com/tendermint/tendermint/abci/types"
Expand Down Expand Up @@ -43,7 +45,7 @@ func (idx *BlockerIndexer) Has(height int64) (bool, error) {
}

_, err = idx.store.Get(key)
if errors.Is(err, store.ErrKeyNotFound) {
if errors.Is(err, gerr.ErrNotFound) {
return false, nil
}
return err == nil, err
Expand Down
7 changes: 3 additions & 4 deletions store/badger.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package store
import (
"errors"

"github.com/dymensionxyz/dymint/gerr"

"github.com/dgraph-io/badger/v3"
)

Expand All @@ -11,9 +13,6 @@ var (
_ KVBatch = &BadgerBatch{}
)

// ErrKeyNotFound is returned if key is not found in KVStore.
var ErrKeyNotFound = errors.New("key not found")

// BadgerKV is a implementation of KVStore using Badger v3.
type BadgerKV struct {
db *badger.DB
Expand All @@ -25,7 +24,7 @@ func (b *BadgerKV) Get(key []byte) ([]byte, error) {
defer txn.Discard()
item, err := txn.Get(key)
if errors.Is(err, badger.ErrKeyNotFound) {
return nil, ErrKeyNotFound
return nil, gerr.ErrNotFound
}
if err != nil {
return nil, err
Expand Down
4 changes: 3 additions & 1 deletion store/badger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"errors"
"testing"

"github.com/dymensionxyz/dymint/gerr"

"github.com/dgraph-io/badger/v3"
)

Expand All @@ -16,7 +18,7 @@ func TestGetErrors(t *testing.T) {
err error
}{
{"empty key", []byte{}, badger.ErrEmptyKey},
{"not found key", []byte("missing key"), ErrKeyNotFound},
{"not found key", []byte("missing key"), gerr.ErrNotFound},
}

for _, tt := range tc {
Expand Down
4 changes: 3 additions & 1 deletion store/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"os"
"testing"

"github.com/dymensionxyz/dymint/gerr"

abcitypes "github.com/tendermint/tendermint/abci/types"
tmstate "github.com/tendermint/tendermint/proto/tendermint/state"

Expand Down Expand Up @@ -186,7 +188,7 @@ func TestBatch(t *testing.T) {
assert.NoError(err)

resp, err := s.LoadBlockResponses(1)
assert.EqualError(err, "retrieve block results from height 1: key not found") // TODO: use errors.Is
assert.Error(err, gerr.ErrNotFound)
assert.Nil(resp)

err = batch.Commit()
Expand Down

0 comments on commit 60e221f

Please sign in to comment.