Skip to content

Commit

Permalink
ci: improve error checking (errcheck linter) (cosmos#11195)
Browse files Browse the repository at this point in the history
## Description

Implements part of cosmos#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)
  • Loading branch information
julienrbrt committed Apr 13, 2022
1 parent f9e0321 commit 2b54693
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 20 deletions.
18 changes: 15 additions & 3 deletions export.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package simapp

import (
"encoding/json"
"fmt"
"log"

tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
15 changes: 5 additions & 10 deletions sim_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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())
Expand Down Expand Up @@ -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())
Expand Down
10 changes: 5 additions & 5 deletions sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}()

Expand Down Expand Up @@ -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))
}()

Expand Down Expand Up @@ -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))
}()

Expand Down Expand Up @@ -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))
}()

Expand Down Expand Up @@ -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))
}()

Expand Down
8 changes: 6 additions & 2 deletions simd/cmd/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2b54693

Please sign in to comment.