mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-07 05:46:32 +00:00
lint: add errchecks (#5316)
## Description Work towards enabling errcheck ref #5059
This commit is contained in:
@@ -252,7 +252,9 @@ func BlockFromProto(bp *tmproto.Block) (*Block, error) {
|
||||
return nil, err
|
||||
}
|
||||
b.Data = data
|
||||
b.Evidence.FromProto(&bp.Evidence)
|
||||
if err := b.Evidence.FromProto(&bp.Evidence); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if bp.LastCommit != nil {
|
||||
lc, err := CommitFromProto(bp.LastCommit)
|
||||
|
||||
@@ -173,8 +173,8 @@ func makeBlockIDRandom() BlockID {
|
||||
blockHash = make([]byte, tmhash.Size)
|
||||
partSetHash = make([]byte, tmhash.Size)
|
||||
)
|
||||
rand.Read(blockHash)
|
||||
rand.Read(partSetHash)
|
||||
rand.Read(blockHash) //nolint: errcheck // ignore errcheck for read
|
||||
rand.Read(partSetHash) //nolint: errcheck // ignore errcheck for read
|
||||
return BlockID{blockHash, PartSetHeader{123, partSetHash}}
|
||||
}
|
||||
|
||||
|
||||
@@ -59,7 +59,9 @@ func (b *EventBus) OnStart() error {
|
||||
}
|
||||
|
||||
func (b *EventBus) OnStop() {
|
||||
b.pubsub.Stop()
|
||||
if err := b.pubsub.Stop(); err != nil {
|
||||
b.pubsub.Logger.Error("error trying to stop eventBus", "error", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (b *EventBus) NumClients() int {
|
||||
|
||||
@@ -20,7 +20,11 @@ func TestEventBusPublishEventTx(t *testing.T) {
|
||||
eventBus := NewEventBus()
|
||||
err := eventBus.Start()
|
||||
require.NoError(t, err)
|
||||
defer eventBus.Stop()
|
||||
t.Cleanup(func() {
|
||||
if err := eventBus.Stop(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
})
|
||||
|
||||
tx := Tx("foo")
|
||||
result := abci.ResponseDeliverTx{
|
||||
@@ -65,7 +69,11 @@ func TestEventBusPublishEventNewBlock(t *testing.T) {
|
||||
eventBus := NewEventBus()
|
||||
err := eventBus.Start()
|
||||
require.NoError(t, err)
|
||||
defer eventBus.Stop()
|
||||
t.Cleanup(func() {
|
||||
if err := eventBus.Stop(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
})
|
||||
|
||||
block := MakeBlock(0, []Tx{}, nil, []Evidence{})
|
||||
resultBeginBlock := abci.ResponseBeginBlock{
|
||||
@@ -112,7 +120,11 @@ func TestEventBusPublishEventTxDuplicateKeys(t *testing.T) {
|
||||
eventBus := NewEventBus()
|
||||
err := eventBus.Start()
|
||||
require.NoError(t, err)
|
||||
defer eventBus.Stop()
|
||||
t.Cleanup(func() {
|
||||
if err := eventBus.Stop(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
})
|
||||
|
||||
tx := Tx("foo")
|
||||
result := abci.ResponseDeliverTx{
|
||||
@@ -216,7 +228,11 @@ func TestEventBusPublishEventNewBlockHeader(t *testing.T) {
|
||||
eventBus := NewEventBus()
|
||||
err := eventBus.Start()
|
||||
require.NoError(t, err)
|
||||
defer eventBus.Stop()
|
||||
t.Cleanup(func() {
|
||||
if err := eventBus.Stop(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
})
|
||||
|
||||
block := MakeBlock(0, []Tx{}, nil, []Evidence{})
|
||||
resultBeginBlock := abci.ResponseBeginBlock{
|
||||
@@ -263,7 +279,11 @@ func TestEventBusPublishEventNewEvidence(t *testing.T) {
|
||||
eventBus := NewEventBus()
|
||||
err := eventBus.Start()
|
||||
require.NoError(t, err)
|
||||
defer eventBus.Stop()
|
||||
t.Cleanup(func() {
|
||||
if err := eventBus.Stop(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
})
|
||||
|
||||
ev := NewMockDuplicateVoteEvidence(1, time.Now(), "test-chain-id")
|
||||
|
||||
@@ -297,7 +317,11 @@ func TestEventBusPublish(t *testing.T) {
|
||||
eventBus := NewEventBus()
|
||||
err := eventBus.Start()
|
||||
require.NoError(t, err)
|
||||
defer eventBus.Stop()
|
||||
t.Cleanup(func() {
|
||||
if err := eventBus.Stop(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
})
|
||||
|
||||
const numEventsExpected = 14
|
||||
|
||||
@@ -389,8 +413,15 @@ func benchmarkEventBus(numClients int, randQueries bool, randEvents bool, b *tes
|
||||
rand.Seed(time.Now().Unix())
|
||||
|
||||
eventBus := NewEventBusWithBufferCapacity(0) // set buffer capacity to 0 so we are not testing cache
|
||||
eventBus.Start()
|
||||
defer eventBus.Stop()
|
||||
err := eventBus.Start()
|
||||
if err != nil {
|
||||
b.Error(err)
|
||||
}
|
||||
b.Cleanup(func() {
|
||||
if err := eventBus.Stop(); err != nil {
|
||||
b.Error(err)
|
||||
}
|
||||
})
|
||||
|
||||
ctx := context.Background()
|
||||
q := EventQueryNewBlock
|
||||
@@ -423,7 +454,10 @@ func benchmarkEventBus(numClients int, randQueries bool, randEvents bool, b *tes
|
||||
eventType = randEvent()
|
||||
}
|
||||
|
||||
eventBus.Publish(eventType, EventDataString("Gamora"))
|
||||
err := eventBus.Publish(eventType, EventDataString("Gamora"))
|
||||
if err != nil {
|
||||
b.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -129,7 +129,8 @@ func TestGenesisSaveAs(t *testing.T) {
|
||||
genDoc := randomGenesisDoc()
|
||||
|
||||
// save
|
||||
genDoc.SaveAs(tmpfile.Name())
|
||||
err = genDoc.SaveAs(tmpfile.Name())
|
||||
require.NoError(t, err)
|
||||
stat, err := tmpfile.Stat()
|
||||
require.NoError(t, err)
|
||||
if err != nil && stat.Size() <= 0 {
|
||||
|
||||
@@ -150,7 +150,10 @@ func HashConsensusParams(params tmproto.ConsensusParams) []byte {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
hasher.Write(bz)
|
||||
_, err = hasher.Write(bz)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return hasher.Sum(nil)
|
||||
}
|
||||
|
||||
|
||||
@@ -307,7 +307,8 @@ func TestVoteSet_Conflicts(t *testing.T) {
|
||||
}
|
||||
|
||||
// start tracking blockHash1
|
||||
voteSet.SetPeerMaj23("peerA", BlockID{blockHash1, PartSetHeader{}})
|
||||
err = voteSet.SetPeerMaj23("peerA", BlockID{blockHash1, PartSetHeader{}})
|
||||
require.NoError(t, err)
|
||||
|
||||
// val0 votes again for blockHash1.
|
||||
{
|
||||
@@ -318,7 +319,8 @@ func TestVoteSet_Conflicts(t *testing.T) {
|
||||
}
|
||||
|
||||
// attempt tracking blockHash2, should fail because already set for peerA.
|
||||
voteSet.SetPeerMaj23("peerA", BlockID{blockHash2, PartSetHeader{}})
|
||||
err = voteSet.SetPeerMaj23("peerA", BlockID{blockHash2, PartSetHeader{}})
|
||||
require.Error(t, err)
|
||||
|
||||
// val0 votes again for blockHash1.
|
||||
{
|
||||
@@ -369,7 +371,8 @@ func TestVoteSet_Conflicts(t *testing.T) {
|
||||
}
|
||||
|
||||
// now attempt tracking blockHash1
|
||||
voteSet.SetPeerMaj23("peerB", BlockID{blockHash1, PartSetHeader{}})
|
||||
err = voteSet.SetPeerMaj23("peerB", BlockID{blockHash1, PartSetHeader{}})
|
||||
require.NoError(t, err)
|
||||
|
||||
// val2 votes for blockHash1.
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user