Enable nilerr linter & fix findings (#12270)

* Enable nilerr linter & fix findings

* Deal with other findings

* Fix another finding that I missed somehow

* Fix another another issue

Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com>

* Update tests to expect error

---------

Co-authored-by: Radosław Kapka <rkapka@wp.pl>
Co-authored-by: terencechain <terence@prysmaticlabs.com>
Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com>
This commit is contained in:
Justin Traglia 2023-04-18 15:53:16 -05:00 committed by GitHub
parent 00001c8628
commit b6181f8d1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 17 additions and 13 deletions

View File

@ -17,6 +17,7 @@ linters:
- errcheck
- gosimple
- gocognit
- nilerr
- whitespace
- misspell

View File

@ -36,7 +36,7 @@ func IsCurrentPeriodSyncCommittee(
if err == cache.ErrNonExistingSyncCommitteeKey {
val, err := st.ValidatorAtIndex(valIdx)
if err != nil {
return false, nil
return false, err
}
committee, err := st.CurrentSyncCommittee()
if err != nil {
@ -73,7 +73,7 @@ func IsNextPeriodSyncCommittee(
if err == cache.ErrNonExistingSyncCommitteeKey {
val, err := st.ValidatorAtIndex(valIdx)
if err != nil {
return false, nil
return false, err
}
committee, err := st.NextSyncCommittee()
if err != nil {
@ -100,7 +100,7 @@ func CurrentPeriodSyncSubcommitteeIndices(
if err == cache.ErrNonExistingSyncCommitteeKey {
val, err := st.ValidatorAtIndex(valIdx)
if err != nil {
return nil, nil
return nil, err
}
committee, err := st.CurrentSyncCommittee()
if err != nil {
@ -134,7 +134,7 @@ func NextPeriodSyncSubcommitteeIndices(
if err == cache.ErrNonExistingSyncCommitteeKey {
val, err := st.ValidatorAtIndex(valIdx)
if err != nil {
return nil, nil
return nil, err
}
committee, err := st.NextSyncCommittee()
if err != nil {

View File

@ -94,7 +94,7 @@ func TestIsCurrentEpochSyncCommittee_DoesNotExist(t *testing.T) {
require.NoError(t, state.SetNextSyncCommittee(syncCommittee))
ok, err := IsCurrentPeriodSyncCommittee(state, 12390192)
require.NoError(t, err)
require.ErrorContains(t, "index 12390192 out of range", err)
require.Equal(t, false, ok)
}
@ -176,7 +176,7 @@ func TestIsNextEpochSyncCommittee_DoesNotExist(t *testing.T) {
require.NoError(t, state.SetNextSyncCommittee(syncCommittee))
ok, err := IsNextPeriodSyncCommittee(state, 120391029)
require.NoError(t, err)
require.ErrorContains(t, "index 120391029 out of range", err)
require.Equal(t, false, ok)
}
@ -273,7 +273,7 @@ func TestCurrentEpochSyncSubcommitteeIndices_DoesNotExist(t *testing.T) {
require.NoError(t, state.SetNextSyncCommittee(syncCommittee))
index, err := CurrentPeriodSyncSubcommitteeIndices(state, 129301923)
require.NoError(t, err)
require.ErrorContains(t, "index 129301923 out of range", err)
require.DeepEqual(t, []primitives.CommitteeIndex(nil), index)
}
@ -356,7 +356,7 @@ func TestNextEpochSyncSubcommitteeIndices_DoesNotExist(t *testing.T) {
require.NoError(t, state.SetNextSyncCommittee(syncCommittee))
index, err := NextPeriodSyncSubcommitteeIndices(state, 21093019)
require.NoError(t, err)
require.ErrorContains(t, "index 21093019 out of range", err)
require.DeepEqual(t, []primitives.CommitteeIndex(nil), index)
}

View File

@ -301,6 +301,7 @@ func (ns *Server) GetHealth(ctx context.Context, _ *emptypb.Empty) (*emptypb.Emp
if ns.SyncChecker.Syncing() || ns.SyncChecker.Initialized() {
if err := grpc.SetHeader(ctx, metadata.Pairs(grpcutil.HttpCodeMetadataKey, strconv.Itoa(http.StatusPartialContent))); err != nil {
// We return a positive result because failing to set a non-gRPC related header should not cause the gRPC call to fail.
//nolint:nilerr
return &emptypb.Empty{}, nil
}
return &emptypb.Empty{}, nil

View File

@ -22,6 +22,7 @@ func (m *MockBlocker) Block(_ context.Context, b []byte) (interfaces.ReadOnlySig
}
slotNumber, parseErr := strconv.ParseUint(string(b), 10, 64)
if parseErr != nil {
//nolint:nilerr
return m.BlockToReturn, nil
}
return m.SlotBlockMap[primitives.Slot(slotNumber)], nil

View File

@ -296,7 +296,7 @@ func (f *blocksFetcher) fetchBlocksFromPeer(
blocks, err := f.requestBlocks(ctx, req, peers[i])
if err == nil {
f.p2p.Peers().Scorers().BlockProviderScorer().Touch(peers[i])
return blocks, peers[i], err
return blocks, peers[i], nil
} else {
log.WithError(err).Debug("Could not request blocks by range")
}

View File

@ -110,14 +110,13 @@ func SendTransaction(client *rpc.Client, key *ecdsa.PrivateKey, f *filler.Filler
g.Go(func() error {
tx, err := txfuzz.RandomValidTx(client, f, sender, nonce+index, gasPrice, nil, al)
if err != nil {
return nil
return err
}
signedTx, err := types.SignTx(tx, types.NewLondonSigner(chainid), key)
if err != nil {
return nil
return err
}
err = backend.SendTransaction(context.Background(), signedTx)
return nil
return backend.SendTransaction(context.Background(), signedTx)
})
}
return g.Wait()

View File

@ -70,6 +70,7 @@ func (s *Server) registerBeaconClient() error {
func (s *Server) GetBeaconStatus(ctx context.Context, _ *empty.Empty) (*validatorpb.BeaconStatusResponse, error) {
syncStatus, err := s.beaconNodeClient.GetSyncStatus(ctx, &emptypb.Empty{})
if err != nil {
//nolint:nilerr
return &validatorpb.BeaconStatusResponse{
BeaconNodeEndpoint: s.nodeGatewayEndpoint,
Connected: false,

View File

@ -19,6 +19,7 @@ import (
func (s *Server) GetBeaconNodeConnection(ctx context.Context, _ *emptypb.Empty) (*validatorpb.NodeConnectionResponse, error) {
syncStatus, err := s.syncChecker.Syncing(ctx)
if err != nil || s.validatorService.Status() != nil {
//nolint:nilerr
return &validatorpb.NodeConnectionResponse{
GenesisTime: 0,
BeaconNodeEndpoint: s.nodeGatewayEndpoint,