ci: improve error checking (errcheck linter) (#11195)

## Description

Implements part of #7258

Check some of currently unchecked errors.

- [x] baseapp
- [x] client
- [x] codec
- [x] crypto
- [x] server
- [x] simapp
- [ ] snapshots
- [ ] store
- [x] testutil
- [ ] types
- [ ] modules

---

### Author Checklist

*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*

I have...

- [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules)
- [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [ ] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*

I have...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed 
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
This commit is contained in:
Julien Robert
2022-04-13 06:46:51 +00:00
committed by GitHub
parent fed09c593a
commit 1fe59eb22a
39 changed files with 240 additions and 162 deletions
+15 -3
View File
@@ -2,6 +2,7 @@ package simapp
import (
"encoding/json"
"fmt"
"log"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
@@ -125,8 +126,16 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []
if err != nil {
panic(err)
}
app.DistrKeeper.Hooks().BeforeDelegationCreated(ctx, delAddr, valAddr)
app.DistrKeeper.Hooks().AfterDelegationModified(ctx, delAddr, valAddr)
if err := app.DistrKeeper.Hooks().BeforeDelegationCreated(ctx, delAddr, valAddr); err != nil {
// never called as BeforeDelegationCreated always returns nil
panic(fmt.Errorf("error while incrementing period: %w", err))
}
if err := app.DistrKeeper.Hooks().AfterDelegationModified(ctx, delAddr, valAddr); err != nil {
// never called as AfterDelegationModified always returns nil
panic(fmt.Errorf("error while creating a new delegation period record: %w", err))
}
}
// reset context height
@@ -174,7 +183,10 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []
counter++
}
iter.Close()
if err := iter.Close(); err != nil {
app.Logger().Error("error while closing the key-value store reverse prefix iterator: ", err)
return
}
_, err := app.StakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx)
if err != nil {
+5 -10
View File
@@ -5,6 +5,7 @@ import (
"os"
"testing"
"github.com/stretchr/testify/require"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
@@ -25,11 +26,8 @@ func BenchmarkFullAppSimulation(b *testing.B) {
}
defer func() {
db.Close()
err = os.RemoveAll(dir)
if err != nil {
b.Fatal(err)
}
require.NoError(b, db.Close())
require.NoError(b, os.RemoveAll(dir))
}()
app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeTestEncodingConfig(), EmptyAppOptions{}, interBlockCacheOpt())
@@ -75,11 +73,8 @@ func BenchmarkInvariants(b *testing.B) {
config.AllInvariants = false
defer func() {
db.Close()
err = os.RemoveAll(dir)
if err != nil {
b.Fatal(err)
}
require.NoError(b, db.Close())
require.NoError(b, os.RemoveAll(dir))
}()
app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeTestEncodingConfig(), EmptyAppOptions{}, interBlockCacheOpt())
+5 -5
View File
@@ -66,7 +66,7 @@ func TestFullAppSimulation(t *testing.T) {
require.NoError(t, err, "simulation setup failed")
defer func() {
db.Close()
require.NoError(t, db.Close())
require.NoError(t, os.RemoveAll(dir))
}()
@@ -104,7 +104,7 @@ func TestAppImportExport(t *testing.T) {
require.NoError(t, err, "simulation setup failed")
defer func() {
db.Close()
require.NoError(t, db.Close())
require.NoError(t, os.RemoveAll(dir))
}()
@@ -144,7 +144,7 @@ func TestAppImportExport(t *testing.T) {
require.NoError(t, err, "simulation setup failed")
defer func() {
newDB.Close()
require.NoError(t, newDB.Close())
require.NoError(t, os.RemoveAll(newDir))
}()
@@ -211,7 +211,7 @@ func TestAppSimulationAfterImport(t *testing.T) {
require.NoError(t, err, "simulation setup failed")
defer func() {
db.Close()
require.NoError(t, db.Close())
require.NoError(t, os.RemoveAll(dir))
}()
@@ -256,7 +256,7 @@ func TestAppSimulationAfterImport(t *testing.T) {
require.NoError(t, err, "simulation setup failed")
defer func() {
newDB.Close()
require.NoError(t, newDB.Close())
require.NoError(t, os.RemoveAll(newDir))
}()
+6 -2
View File
@@ -519,9 +519,13 @@ func startTestnet(cmd *cobra.Command, args startArgs) error {
return err
}
testnet.WaitForHeight(1)
if _, err := testnet.WaitForHeight(1); err != nil {
return err
}
cmd.Println("press the Enter Key to terminate")
fmt.Scanln() // wait for Enter Key
if _, err := fmt.Scanln(); err != nil { // wait for Enter Key
return err
}
testnet.Cleanup()
return nil