Skip to content

Commit

Permalink
Enable lint errcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
pbains committed Nov 23, 2022
1 parent 455eb1a commit 38e4427
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 17 deletions.
6 changes: 5 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
"go.toolsManagement.checkForUpdates": "local",
"go.useLanguageServer": true,
"go.gopath": "/go",
"go.goroot": "/usr/local/go"
"go.goroot": "/usr/local/go",
"go.lintTool": "golangci-lint",
"go.lintFlags": [
"--fast"
]
},
"extensions": [
"golang.Go",
Expand Down
3 changes: 2 additions & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ run:
- integration
- flakes
linters:
enable:
- errcheck
# Disabling linters until we get them fixed up.
disable:
- errcheck
- gosimple
- govet
- ineffassign
Expand Down
4 changes: 3 additions & 1 deletion cmd/testutils/layer1_tx_spammer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,9 @@ func main() {
defer watcher.Close()
if isUsingTestAccounts {
// this function will block for finality delay blocks
tests.FundAccounts(eth, watcher, logger)
if err := tests.FundAccounts(eth, watcher, logger); err != nil {
panic("Unable to fund test accounts")
}
tests.SetNextBlockBaseFee(eth.GetEndpoint(), 100_000_000_000)
}

Expand Down
1 change: 1 addition & 0 deletions consensus/objs/rs.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ func (b *RoundState) TrackExternalConflicts(v *Proposal) {
return
}
// is current
// nolint:errcheck // review error checking for RoundState
b.checkStaleAndConflict(v, false)
}

Expand Down
15 changes: 12 additions & 3 deletions dynamics/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestMock(t *testing.T) {

m := NewTestDB()

m.DB().Update(func(txn *badger.Txn) error {
err := m.DB().Update(func(txn *badger.Txn) error {
_, err := m.GetValue(txn, key)
if !errors.Is(err, ErrKeyNotPresent) {
t.Fatalf("should have failed: %v", err)
Expand All @@ -57,6 +57,9 @@ func TestMock(t *testing.T) {
}
return nil
})
if err != nil {
t.Fatal("unable to complete test")
}

}

Expand All @@ -78,7 +81,7 @@ func TestGetSetNode(t *testing.T) {
db := initializeDB()

node := &Node{}
db.rawDB.Update(func(txn *badger.Txn) error {
err := db.rawDB.Update(func(txn *badger.Txn) error {
err := db.SetNode(txn, node)
if err == nil {
t.Fatal("Should have raised error (1)")
Expand Down Expand Up @@ -117,14 +120,17 @@ func TestGetSetNode(t *testing.T) {
}
return nil
})
if err != nil {
t.Fatal("unable to complete test")
}
}

func TestGetSetLinkedList(t *testing.T) {
t.Parallel()
db := initializeDB()

ll := &LinkedList{}
db.rawDB.Update(func(txn *badger.Txn) error {
err := db.rawDB.Update(func(txn *badger.Txn) error {
err := db.SetLinkedList(txn, ll)
if err == nil {
t.Fatal("Should have raised error (1)")
Expand All @@ -148,4 +154,7 @@ func TestGetSetLinkedList(t *testing.T) {
}
return nil
})
if err != nil {
t.Fatal("unable to complete test")
}
}
10 changes: 8 additions & 2 deletions dynamics/dynamics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,10 @@ func TestStorageInit1(t *testing.T) {
func TestStorageInitFromScratch(t *testing.T) {
t.Parallel()
s := &Storage{}
s.Init(NewTestDB(), newLogger())
err := s.Init(NewTestDB(), newLogger())
if err != nil {
t.Fatal("Database not initialized")
}

// since there's no node, the starting channel should be closed and no request
// against the storage should be allowed
Expand All @@ -171,7 +174,10 @@ func TestStorageInitWithPersistance(t *testing.T) {
}

s2 := &Storage{}
s2.Init(s.database.rawDB, s.logger)
err = s2.Init(s.database.rawDB, s.logger)
if err != nil {
t.Fatal("unable to initialize storage")
}

// Check dynamicValues == standardParameters
storageDVBytes, err := s2.DynamicValues.Marshal()
Expand Down
5 changes: 4 additions & 1 deletion layer1/executor/task_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ func (te *TaskExecutor) handleTaskExecution(task tasks.Task, name string, taskId
// Clean up in case the task was killed
if task.WasKilled() {
task.GetLogger().Trace("task was externally killed, removing tx backup")
te.removeTxBackup(task.GetId())
err := te.removeTxBackup(task.GetId())
if err != nil {
task.GetLogger().Error("removal of tx back up failure")
}
}

if errors.Is(err, tasks.ErrTaskExecutionMechanismClosed) {
Expand Down
20 changes: 14 additions & 6 deletions layer1/executor/task_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import (
"context"
"encoding/json"
"errors"
"github.com/alicenet/alicenet/layer1/executor/tasks/dkg"
"github.com/alicenet/alicenet/layer1/executor/tasks/snapshots"
"reflect"
"strings"
"sync"
"time"

"github.com/alicenet/alicenet/layer1/executor/tasks/dkg"
"github.com/alicenet/alicenet/layer1/executor/tasks/snapshots"

"github.com/dgraph-io/badger/v2"
"github.com/sirupsen/logrus"

Expand Down Expand Up @@ -121,7 +122,7 @@ func (tm *TaskManager) eventLoop() {

case taskRequest, ok := <-tm.requestChan:
if !ok {
tm.onError(ErrReceivedRequestClosedChan)
_ = tm.onError(ErrReceivedRequestClosedChan)
return
}
if taskRequest.response == nil {
Expand Down Expand Up @@ -160,10 +161,14 @@ func (tm *TaskManager) eventLoop() {
}
}
taskRequest.response.sendResponse(response)
tm.persistState()
err := tm.persistState()
if err != nil {
tm.logger.WithError(err).Logger.Warn("presist state failed")
}
case taskResponse, ok := <-tm.responseChan.erChan:
if !ok {
tm.onError(ErrReceivedResponseClosedChan)
//nolint:errcheck // Intentionally logging and swallowing error
_ = tm.onError(ErrReceivedResponseClosedChan)
return
}

Expand All @@ -173,7 +178,10 @@ func (tm *TaskManager) eventLoop() {
tm.logger.WithError(err).Errorf("Failed to processTaskResponse %v", taskResponse)
continue
}
tm.persistState()
err = tm.persistState()
if err != nil {
tm.logger.WithError(err).Errorf("Unable to presistState")
}
case <-processingTime:
tm.logger.Trace("processing latest height")
networkCtx, networkCf := context.WithTimeout(context.Background(), tasks.ManagerNetworkTimeout)
Expand Down
6 changes: 4 additions & 2 deletions layer1/executor/tasks/tests/register_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@ func TestRegisterTask_Group_1_Bad1(t *testing.T) {
dkgState.TransportPrivateKey = big.NewInt(0)
// Mess up public key; this should fail because it is invalid
dkgState.TransportPublicKey = [2]*big.Int{big.NewInt(0), big.NewInt(1)}
state.SaveDkgState(dkgDb, dkgState)
err = state.SaveDkgState(dkgDb, dkgState)
assert.NotNil(t, err)
_, err = registrationTask.Execute(ctx)
assert.NotNil(t, err)
}
Expand Down Expand Up @@ -299,7 +300,8 @@ func TestRegisterTask_Group_2_Bad2(t *testing.T) {
dkgState.TransportPrivateKey = big.NewInt(0)
// Mess up public key; this should fail because it is invalid (the identity element)
dkgState.TransportPublicKey = [2]*big.Int{big.NewInt(0), big.NewInt(0)}
state.SaveDkgState(dkgDb, dkgState)
err = state.SaveDkgState(dkgDb, dkgState)
assert.NotNil(t, err)
_, err = registrationTask.Execute(ctx)
assert.NotNil(t, err)
}
Expand Down

0 comments on commit 38e4427

Please sign in to comment.