Skip to content

Commit bff54b5

Browse files
committed
Add errorlint linter with errorf setting disabled
1 parent e50cedc commit bff54b5

File tree

7 files changed

+32
-30
lines changed

7 files changed

+32
-30
lines changed

.golangci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,21 @@ run:
55

66
linters:
77
enable:
8+
- errorlint
89
- goimports
910
- ineffassign
1011
- misspell
1112
- unconvert
1213
- whitespace
1314

15+
linters-settings:
16+
errorlint:
17+
errorf: false
18+
1419
issues:
1520
exclude-rules:
1621
- path-except: "(plugin\\/.+\\.go|.+_ext\\.go)"
1722
linters:
1823
- errcheck
24+
- errorlint
1925
- staticcheck

plugin/evm/atomic_backend.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package evm
55

66
import (
77
"encoding/binary"
8+
"errors"
89
"fmt"
910
"time"
1011

@@ -226,7 +227,7 @@ func (a *atomicBackend) initialize(lastAcceptedHeight uint64) error {
226227
// the range of operations that were added to the trie without being executed on shared memory.
227228
func (a *atomicBackend) ApplyToSharedMemory(lastAcceptedBlock uint64) error {
228229
sharedMemoryCursor, err := a.metadataDB.Get(appliedSharedMemoryCursorKey)
229-
if err == database.ErrNotFound {
230+
if errors.Is(err, database.ErrNotFound) {
230231
return nil
231232
} else if err != nil {
232233
return err

plugin/evm/atomic_trie.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package evm
55

66
import (
7+
"errors"
78
"fmt"
89
"time"
910

@@ -187,7 +188,7 @@ func lastCommittedRootIfExists(db avalanchedatabase.Database) (common.Hash, uint
187188
// read the last committed entry if it exists and set the root hash
188189
lastCommittedHeightBytes, err := db.Get(lastCommittedKey)
189190
switch {
190-
case err == avalanchedatabase.ErrNotFound:
191+
case errors.Is(err, avalanchedatabase.ErrNotFound):
191192
return common.Hash{}, 0, nil
192193
case err != nil:
193194
return common.Hash{}, 0, err
@@ -309,7 +310,7 @@ func getRoot(metadataDB avalanchedatabase.Database, height uint64) (common.Hash,
309310
heightBytes := avalanchedatabase.PackUInt64(height)
310311
hash, err := metadataDB.Get(heightBytes)
311312
switch {
312-
case err == avalanchedatabase.ErrNotFound:
313+
case errors.Is(err, avalanchedatabase.ErrNotFound):
313314
return common.Hash{}, nil
314315
case err != nil:
315316
return common.Hash{}, err

plugin/evm/atomic_tx_repository.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package evm
55

66
import (
77
"encoding/binary"
8+
"errors"
89
"fmt"
910
"time"
1011

@@ -94,12 +95,9 @@ func (a *atomicTxRepository) initializeHeightIndex(lastAcceptedHeight uint64) er
9495
// if we are part way through a migration.
9596
var lastTxID ids.ID
9697
indexHeightBytes, err := a.atomicRepoMetadataDB.Get(maxIndexedHeightKey)
97-
switch err {
98-
case nil:
99-
break
100-
case database.ErrNotFound:
101-
break
102-
default: // unexpected value in the database
98+
switch {
99+
case errors.Is(err, database.ErrNotFound):
100+
case err != nil: // unexpected value in the database
103101
return fmt.Errorf("found invalid value at max indexed height: %v", indexHeightBytes)
104102
}
105103

@@ -274,11 +272,12 @@ func (a *atomicTxRepository) write(height uint64, txs []*atomic.Tx, bonus bool)
274272
if len(txs) > 0 {
275273
for _, tx := range txs {
276274
if bonus {
277-
switch _, _, err := a.GetByTxID(tx.ID()); err {
278-
case nil:
275+
_, _, err := a.GetByTxID(tx.ID())
276+
switch {
277+
case err == nil:
279278
// avoid overwriting existing value if [bonus] is true
280279
continue
281-
case database.ErrNotFound:
280+
case errors.Is(err, database.ErrNotFound):
282281
// no existing value to overwrite, proceed as normal
283282
default:
284283
// unexpected error
@@ -338,7 +337,7 @@ func (a *atomicTxRepository) indexTxsAtHeight(heightBytes []byte, txs []*atomic.
338337
// by txID into the height -> txs index.
339338
func (a *atomicTxRepository) appendTxToHeightIndex(heightBytes []byte, tx *atomic.Tx) error {
340339
txs, err := a.getByHeightBytes(heightBytes)
341-
if err != nil && err != database.ErrNotFound {
340+
if err != nil && !errors.Is(err, database.ErrNotFound) {
342341
return err
343342
}
344343

plugin/evm/tx_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"strings"
1010
"testing"
1111

12+
"github.com/stretchr/testify/assert"
1213
"github.com/stretchr/testify/require"
1314

1415
"github.com/ethereum/go-ethereum/common"
@@ -51,9 +52,7 @@ func TestCalculateDynamicFee(t *testing.T) {
5152
t.Fatalf("Expected value: %d, found: %d", test.expectedValue, cost)
5253
}
5354
} else {
54-
if err != test.expectedErr {
55-
t.Fatalf("Expected error: %s, found error: %s", test.expectedErr, err)
56-
}
55+
assert.ErrorIs(t, err, test.expectedErr)
5756
}
5857
}
5958
}

plugin/evm/vm.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1534,7 +1534,7 @@ func (vm *VM) CreateStaticHandlers(context.Context) (map[string]http.Handler, er
15341534
func (vm *VM) getAtomicTx(txID ids.ID) (*atomic.Tx, atomic.Status, uint64, error) {
15351535
if tx, height, err := vm.atomicTxRepository.GetByTxID(txID); err == nil {
15361536
return tx, atomic.Accepted, height, nil
1537-
} else if err != database.ErrNotFound {
1537+
} else if !errors.Is(err, database.ErrNotFound) {
15381538
return nil, atomic.Unknown, 0, err
15391539
}
15401540
tx, dropped, found := vm.mempool.GetTx(txID)
@@ -1763,7 +1763,7 @@ func (vm *VM) readLastAccepted() (common.Hash, uint64, error) {
17631763
// initialize state with the genesis block.
17641764
lastAcceptedBytes, lastAcceptedErr := vm.acceptedBlockDB.Get(lastAcceptedKey)
17651765
switch {
1766-
case lastAcceptedErr == database.ErrNotFound:
1766+
case errors.Is(lastAcceptedErr, database.ErrNotFound):
17671767
// If there is nothing in the database, return the genesis block hash and height
17681768
return vm.genesisHash, 0, nil
17691769
case lastAcceptedErr != nil:

plugin/evm/vm_test.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1815,9 +1815,8 @@ func TestNonCanonicalAccept(t *testing.T) {
18151815
t.Fatalf("Block failed verification on VM1: %s", err)
18161816
}
18171817

1818-
if _, err := vm1.GetBlockIDAtHeight(context.Background(), vm1BlkA.Height()); err != database.ErrNotFound {
1819-
t.Fatalf("Expected unaccepted block not to be indexed by height, but found %s", err)
1820-
}
1818+
_, err = vm1.GetBlockIDAtHeight(context.Background(), vm1BlkA.Height())
1819+
assert.NotErrorIs(t, err, database.ErrNotFound, "Expected unaccepted block not to be indexed by height")
18211820

18221821
if err := vm1.SetPreference(context.Background(), vm1BlkA.ID()); err != nil {
18231822
t.Fatal(err)
@@ -1830,9 +1829,8 @@ func TestNonCanonicalAccept(t *testing.T) {
18301829
if err := vm2BlkA.Verify(context.Background()); err != nil {
18311830
t.Fatalf("Block failed verification on VM2: %s", err)
18321831
}
1833-
if _, err := vm2.GetBlockIDAtHeight(context.Background(), vm2BlkA.Height()); err != database.ErrNotFound {
1834-
t.Fatalf("Expected unaccepted block not to be indexed by height, but found %s", err)
1835-
}
1832+
_, err = vm2.GetBlockIDAtHeight(context.Background(), vm2BlkA.Height())
1833+
assert.NotErrorIs(t, err, database.ErrNotFound, "Expected unaccepted block not to be indexed by height")
18361834
if err := vm2.SetPreference(context.Background(), vm2BlkA.ID()); err != nil {
18371835
t.Fatal(err)
18381836
}
@@ -1896,9 +1894,8 @@ func TestNonCanonicalAccept(t *testing.T) {
18961894
t.Fatal(err)
18971895
}
18981896

1899-
if _, err := vm1.GetBlockIDAtHeight(context.Background(), vm1BlkB.Height()); err != database.ErrNotFound {
1900-
t.Fatalf("Expected unaccepted block not to be indexed by height, but found %s", err)
1901-
}
1897+
_, err = vm1.GetBlockIDAtHeight(context.Background(), vm1BlkB.Height())
1898+
assert.NotErrorIs(t, err, database.ErrNotFound, "Expected unaccepted block not to be indexed by height")
19021899

19031900
if err := vm1.SetPreference(context.Background(), vm1BlkB.ID()); err != nil {
19041901
t.Fatal(err)
@@ -1934,9 +1931,8 @@ func TestNonCanonicalAccept(t *testing.T) {
19341931
t.Fatalf("Block failed verification on VM1: %s", err)
19351932
}
19361933

1937-
if _, err := vm1.GetBlockIDAtHeight(context.Background(), vm1BlkC.Height()); err != database.ErrNotFound {
1938-
t.Fatalf("Expected unaccepted block not to be indexed by height, but found %s", err)
1939-
}
1934+
_, err = vm1.GetBlockIDAtHeight(context.Background(), vm1BlkC.Height())
1935+
assert.NotErrorIs(t, err, database.ErrNotFound, "Expected unaccepted block not to be indexed by height")
19401936

19411937
if err := vm1BlkC.Accept(context.Background()); err != nil {
19421938
t.Fatalf("VM1 failed to accept block: %s", err)

0 commit comments

Comments
 (0)