Skip to content

Commit

Permalink
Enable nilerr linter & fix findings (prysmaticlabs#12270)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* Update tests to expect error

---------

Co-authored-by: Radosław Kapka <[email protected]>
Co-authored-by: terencechain <[email protected]>
Co-authored-by: Preston Van Loon <[email protected]>
  • Loading branch information
4 people authored Apr 18, 2023
1 parent 00001c8 commit b6181f8
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 13 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ linters:
- errcheck
- gosimple
- gocognit
- nilerr
- whitespace
- misspell

Expand Down
8 changes: 4 additions & 4 deletions beacon-chain/core/helpers/sync_committee.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions beacon-chain/core/helpers/sync_committee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

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

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

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

Expand Down
1 change: 1 addition & 0 deletions beacon-chain/rpc/eth/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions beacon-chain/rpc/testutil/mock_blocker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/sync/initial-sync/blocks_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
7 changes: 3 additions & 4 deletions testing/endtoend/components/eth1/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions validator/rpc/beacon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions validator/rpc/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit b6181f8

Please sign in to comment.