Skip to content

Commit 110e6bc

Browse files
committed
Add errorlint linter with errorf setting disabled
1 parent f3599dc commit 110e6bc

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
@@ -26,6 +26,11 @@ linters:
2626
- mirror
2727
- tenv
2828
- errcheck
29+
- errorlint
30+
31+
linters-settings:
32+
errorlint:
33+
errorf: false
2934

3035
issues:
3136
exclude-rules:
@@ -37,6 +42,7 @@ issues:
3742
- path-except: "(plugin\\/.+\\.go|.+_ext\\.go)"
3843
linters:
3944
- errcheck
45+
- errorlint
4046
- gosimple
4147
- govet
4248
- 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

@@ -183,7 +184,7 @@ func lastCommittedRootIfExists(db avalanchedatabase.Database) (common.Hash, uint
183184
// read the last committed entry if it exists and set the root hash
184185
lastCommittedHeightBytes, err := db.Get(lastCommittedKey)
185186
switch {
186-
case err == avalanchedatabase.ErrNotFound:
187+
case errors.Is(err, avalanchedatabase.ErrNotFound):
187188
return common.Hash{}, 0, nil
188189
case err != nil:
189190
return common.Hash{}, 0, err
@@ -305,7 +306,7 @@ func getRoot(metadataDB avalanchedatabase.Database, height uint64) (common.Hash,
305306
heightBytes := avalanchedatabase.PackUInt64(height)
306307
hash, err := metadataDB.Get(heightBytes)
307308
switch {
308-
case err == avalanchedatabase.ErrNotFound:
309+
case errors.Is(err, avalanchedatabase.ErrNotFound):
309310
return common.Hash{}, nil
310311
case err != nil:
311312
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
@@ -1523,7 +1523,7 @@ func (vm *VM) CreateStaticHandlers(context.Context) (map[string]http.Handler, er
15231523
func (vm *VM) getAtomicTx(txID ids.ID) (*atomic.Tx, atomic.Status, uint64, error) {
15241524
if tx, height, err := vm.atomicTxRepository.GetByTxID(txID); err == nil {
15251525
return tx, atomic.Accepted, height, nil
1526-
} else if err != database.ErrNotFound {
1526+
} else if !errors.Is(err, database.ErrNotFound) {
15271527
return nil, atomic.Unknown, 0, err
15281528
}
15291529
tx, dropped, found := vm.mempool.GetTx(txID)
@@ -1752,7 +1752,7 @@ func (vm *VM) readLastAccepted() (common.Hash, uint64, error) {
17521752
// initialize state with the genesis block.
17531753
lastAcceptedBytes, lastAcceptedErr := vm.acceptedBlockDB.Get(lastAcceptedKey)
17541754
switch {
1755-
case lastAcceptedErr == database.ErrNotFound:
1755+
case errors.Is(lastAcceptedErr, database.ErrNotFound):
17561756
// If there is nothing in the database, return the genesis block hash and height
17571757
return vm.genesisHash, 0, nil
17581758
case lastAcceptedErr != nil:

plugin/evm/vm_test.go

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

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

18281827
if err := vm1.SetPreference(context.Background(), vm1BlkA.ID()); err != nil {
18291828
t.Fatal(err)
@@ -1836,9 +1835,8 @@ func TestNonCanonicalAccept(t *testing.T) {
18361835
if err := vm2BlkA.Verify(context.Background()); err != nil {
18371836
t.Fatalf("Block failed verification on VM2: %s", err)
18381837
}
1839-
if _, err := vm2.GetBlockIDAtHeight(context.Background(), vm2BlkA.Height()); err != database.ErrNotFound {
1840-
t.Fatalf("Expected unaccepted block not to be indexed by height, but found %s", err)
1841-
}
1838+
_, err = vm2.GetBlockIDAtHeight(context.Background(), vm2BlkA.Height())
1839+
assert.ErrorIs(t, err, database.ErrNotFound, "Expected unaccepted block not to be indexed by height")
18421840
if err := vm2.SetPreference(context.Background(), vm2BlkA.ID()); err != nil {
18431841
t.Fatal(err)
18441842
}
@@ -1902,9 +1900,8 @@ func TestNonCanonicalAccept(t *testing.T) {
19021900
t.Fatal(err)
19031901
}
19041902

1905-
if _, err := vm1.GetBlockIDAtHeight(context.Background(), vm1BlkB.Height()); err != database.ErrNotFound {
1906-
t.Fatalf("Expected unaccepted block not to be indexed by height, but found %s", err)
1907-
}
1903+
_, err = vm1.GetBlockIDAtHeight(context.Background(), vm1BlkB.Height())
1904+
assert.ErrorIs(t, err, database.ErrNotFound, "Expected unaccepted block not to be indexed by height")
19081905

19091906
if err := vm1.SetPreference(context.Background(), vm1BlkB.ID()); err != nil {
19101907
t.Fatal(err)
@@ -1940,9 +1937,8 @@ func TestNonCanonicalAccept(t *testing.T) {
19401937
t.Fatalf("Block failed verification on VM1: %s", err)
19411938
}
19421939

1943-
if _, err := vm1.GetBlockIDAtHeight(context.Background(), vm1BlkC.Height()); err != database.ErrNotFound {
1944-
t.Fatalf("Expected unaccepted block not to be indexed by height, but found %s", err)
1945-
}
1940+
_, err = vm1.GetBlockIDAtHeight(context.Background(), vm1BlkC.Height())
1941+
assert.ErrorIs(t, err, database.ErrNotFound, "Expected unaccepted block not to be indexed by height")
19461942

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

0 commit comments

Comments
 (0)