Skip to content

Commit f381e27

Browse files
authored
CI: enable error-handling linters and fix a few bugs (#6479)
1 parent 978c6e2 commit f381e27

File tree

24 files changed

+72
-128
lines changed

24 files changed

+72
-128
lines changed

.github/workflows/reviewdog.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: "ReviewDog workflow"
22
env:
3-
GOLANGCI_LINT_VERSION: "v2.5.1-0.20251021235302-b99da877a247"
3+
GOLANGCI_LINT_VERSION: "v2.6.0"
44
on:
55
push:
66
branches:

.golangci.yml

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,24 @@ run:
55
linters:
66
default: none
77
enable:
8+
- asciicheck
9+
- bidichk
810
- copyloopvar
911
- dupword
1012
- errcheck
1113
- govet
1214
- ineffassign
15+
- iotamixing
1316
- misspell
1417
- nilerr
18+
- nilnesserr
1519
- nolintlint
1620
- paralleltest
21+
- reassign
1722
- revive
23+
#- sqlclosecheck
1824
- staticcheck
25+
- testifylint
1926
- unused
2027

2128
settings:
@@ -32,13 +39,16 @@ linters:
3239
govet:
3340
# Enables these linters in addition to the default ones.
3441
enable:
42+
- nilness
43+
- reflectvaluecompare
3544
- shadow
45+
- sortslice
46+
- waitgroup
3647
disable:
3748
- buildtag
3849
settings:
3950
printf:
4051
# Comma-separated list of print function names to check (in addition to default, see `go tool vet help printf`).
41-
# Default: []
4252
funcs:
4353
- (github.com/algorand/go-algorand/logging.Logger).Debugf
4454
- (github.com/algorand/go-algorand/logging.Logger).Infof
@@ -87,6 +97,10 @@ linters:
8797
- '-ST1005' # ignore "error strings should not be capitalized"
8898
- '-QF1001' # ignore De Morgan's law suggestions
8999
- '-QF1003' # ignore suggestions to replace if/else chain with switch
100+
testifylint:
101+
enable:
102+
- error-is-as
103+
disable-all: true
90104

91105
exclusions:
92106
generated: lax
@@ -132,15 +146,6 @@ linters:
132146
text: '^empty-block: this block is empty, you can remove it'
133147
- linters: revive
134148
text: '^superfluous-else: if block ends with .* so drop this else and outdent its block'
135-
# Comment this block out for testing linters
136-
- linters:
137-
- errcheck
138-
- govet
139-
- ineffassign
140-
- misspell
141-
- revive
142-
- unused
143-
path: test/linttest/lintissues\.go
144149

145150
issues:
146151
# Work our way back over time to be clean against all these

agreement/fuzzer/networkFacade_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ func (n *NetworkFacade) pushPendingReceivedMessage() bool {
332332
case network.Broadcast:
333333
n.broadcast(storedMsg.tag, storedMsg.data, -1, "NetworkFacade service-%v Broadcast-Action %v %v\n")
334334
default:
335-
panic(nil) // not handled; agreement doesn't currently use this one.
335+
panic(fmt.Sprintf("unhandled network action %v", outMsg.Action))
336336
}
337337

338338
if n.debugMessages {

agreement/pseudonode_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package agreement
1919
import (
2020
"context"
2121
"crypto/sha256"
22-
"errors"
2322
"fmt"
2423
"strings"
2524
"testing"
@@ -520,21 +519,21 @@ func TestPseudonodeNonEnqueuedTasks(t *testing.T) {
520519
for i := 0; i < pseudonodeVerificationBacklog*2; i++ {
521520
ch, err = pb.MakeProposals(context.Background(), startRound, period(i))
522521
if err != nil {
523-
require.ErrorAs(t, errPseudonodeBacklogFull, &err)
522+
require.ErrorIs(t, err, errPseudonodeBacklogFull)
524523
break
525524
}
526525
channels = append(channels, ch)
527526
}
528527
enqueuedProposals := len(channels)
529528
require.Error(t, err, "MakeProposals did not returned an error when being overflowed with requests")
530-
require.True(t, errors.Is(err, errPseudonodeBacklogFull))
529+
require.ErrorIs(t, err, errPseudonodeBacklogFull)
531530

532531
persist := make(chan error)
533532
close(persist)
534533
for i := 0; i < pseudonodeVerificationBacklog*2; i++ {
535534
ch, err = pb.MakeVotes(context.Background(), startRound, period(i), step(i%5), makeProposalValue(period(i), accounts[0].Address()), persist)
536535
if err != nil {
537-
require.ErrorAs(t, errPseudonodeBacklogFull, &err)
536+
require.ErrorIs(t, err, errPseudonodeBacklogFull)
538537
break
539538
}
540539
channels = append(channels, ch)

catchup/universalFetcher_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ func TestUGetBlockWs(t *testing.T) {
7474
block, cert, duration, err = fetcher.fetchBlock(context.Background(), next+1, up)
7575

7676
require.Error(t, err)
77-
require.Error(t, noBlockForRoundError{}, err)
77+
var noBlockErr noBlockForRoundError
78+
require.ErrorAs(t, err, &noBlockErr)
7879
require.Equal(t, next+1, err.(noBlockForRoundError).round)
7980
require.Equal(t, next, err.(noBlockForRoundError).latest)
8081
require.Nil(t, block)
@@ -120,7 +121,8 @@ func TestUGetBlockHTTP(t *testing.T) {
120121

121122
block, cert, duration, err = fetcher.fetchBlock(context.Background(), next+1, net.GetPeers()[0])
122123

123-
require.Error(t, noBlockForRoundError{}, err)
124+
var noBlockErr noBlockForRoundError
125+
require.ErrorAs(t, err, &noBlockErr)
124126
require.Equal(t, next+1, err.(noBlockForRoundError).round)
125127
require.Equal(t, next, err.(noBlockForRoundError).latest)
126128
require.Contains(t, err.Error(), "no block available for given round")

cmd/algorelay/relayCmd.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -524,9 +524,6 @@ func ensureRelayStatus(checkOnly bool, relay eb.Relay, nameDomain string, srvDom
524524
// Returns an array of names starting with the target ip/name and ending with the outermost reference
525525
func getTargetDNSChain(nameEntries map[string]string, target string) (names []string, err error) {
526526
target = strings.ToLower(target)
527-
if err != nil {
528-
return
529-
}
530527

531528
names = append(names, target)
532529
for {

cmd/dispenser/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func dispense(w http.ResponseWriter, r *http.Request) {
136136
targets := r.Form["target"]
137137
if len(targets) != 1 {
138138
log.Printf("Corrupted target argument\n")
139-
http.Error(w, err.Error(), http.StatusInternalServerError)
139+
http.Error(w, "Corrupted target argument", http.StatusBadRequest)
140140
return
141141
}
142142

cmd/tealdbg/local.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,8 @@ func txnGroupFromParams(dp *DebugParams) (txnGroup []transactions.SignedTxn, err
9090

9191
// if conversion failed report all intermediate decoding errors
9292
if err != nil {
93-
if err1 != nil {
94-
log.Printf("Decoding as JSON txn failed: %s", err1.Error())
95-
}
96-
if err2 != nil {
97-
log.Printf("Decoding as JSON txn group failed: %s", err2.Error())
98-
}
93+
log.Printf("Decoding as JSON txn failed: %v", err1)
94+
log.Printf("Decoding as JSON txn group failed: %v", err2)
9995
}
10096

10197
return
@@ -141,12 +137,8 @@ func balanceRecordsFromParams(dp *DebugParams) (records []basics.BalanceRecord,
141137

142138
// if conversion failed report all intermediate decoding errors
143139
if err != nil {
144-
if err1 != nil {
145-
log.Printf("Decoding as JSON record failed: %s", err1.Error())
146-
}
147-
if err2 != nil {
148-
log.Printf("Decoding as JSON array of records failed: %s", err2.Error())
149-
}
140+
log.Printf("Decoding as JSON record failed: %v", err1)
141+
log.Printf("Decoding as JSON array of records failed: %v", err2)
150142
}
151143

152144
return

crypto/merklesignature/merkleSignatureScheme_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package merklesignature
1818

1919
import (
2020
"crypto/rand"
21-
"errors"
2221
"math"
2322
"testing"
2423

@@ -329,7 +328,7 @@ func TestBadRound(t *testing.T) {
329328
err = signer.GetVerifier().VerifyBytes(start+2, msg, &sig)
330329
a.Error(err)
331330
a.ErrorIs(err, ErrSignatureSchemeVerificationFailed)
332-
a.True(errors.Is(err, ErrSignatureSchemeVerificationFailed))
331+
a.ErrorIs(err, ErrSignatureSchemeVerificationFailed)
333332
}
334333

335334
func TestBadMerkleProofInSignature(t *testing.T) {

daemon/algod/api/server/common/test/handlers_test.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package test
1818

1919
import (
20-
"fmt"
2120
"net/http"
2221
"net/http/httptest"
2322
"testing"
@@ -34,11 +33,11 @@ import (
3433

3534
func mockNodeStatusInRangeHelper(
3635
t *testing.T, statusCode MockNodeCatchupStatus,
37-
expectedErr error, expectedStatus node.StatusReport) {
36+
expectedErr string, expectedStatus node.StatusReport) {
3837
mockNodeInstance := makeMockNode(statusCode)
3938
status, err := mockNodeInstance.Status()
40-
if expectedErr != nil {
41-
require.Error(t, err, expectedErr)
39+
if expectedErr != "" {
40+
require.EqualError(t, err, expectedErr)
4241
} else {
4342
require.Equal(t, expectedStatus, status)
4443
}
@@ -48,13 +47,13 @@ func TestMockNodeStatus(t *testing.T) {
4847
partitiontest.PartitionTest(t)
4948

5049
mockNodeStatusInRangeHelper(
51-
t, CaughtUpAndReady, nil, cannedStatusReportCaughtUpAndReadyGolden)
50+
t, CaughtUpAndReady, "", cannedStatusReportCaughtUpAndReadyGolden)
5251
mockNodeStatusInRangeHelper(
53-
t, CatchingUpFast, nil, cannedStatusReportCatchingUpFastGolden)
52+
t, CatchingUpFast, "", cannedStatusReportCatchingUpFastGolden)
5453
mockNodeStatusInRangeHelper(
55-
t, StoppedAtUnsupported, nil, cannedStatusReportStoppedAtUnsupportedGolden)
54+
t, StoppedAtUnsupported, "", cannedStatusReportStoppedAtUnsupportedGolden)
5655
mockNodeStatusInRangeHelper(
57-
t, 399, fmt.Errorf("catchup status out of scope error"), node.StatusReport{})
56+
t, 399, "catchup status out of scope error", node.StatusReport{})
5857
}
5958

6059
func readyEndpointTestHelper(

0 commit comments

Comments
 (0)