Skip to content

Commit 6539304

Browse files
committed
fix: lint errors fulu
1 parent 870268e commit 6539304

File tree

16 files changed

+99
-40
lines changed

16 files changed

+99
-40
lines changed

pkg/coordinator/clients/consensus/rpc/beaconapi.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,11 @@ func (bc *BeaconClient) getJSON(ctx context.Context, requrl string, returnValue
8989
return err
9090
}
9191

92-
defer resp.Body.Close()
92+
defer func() {
93+
if err := resp.Body.Close(); err != nil {
94+
logrus.WithError(err).Warn("failed to close response body")
95+
}
96+
}()
9397

9498
if resp.StatusCode != nethttp.StatusOK {
9599
if resp.StatusCode == nethttp.StatusNotFound {
@@ -140,7 +144,11 @@ func (bc *BeaconClient) postJSON(ctx context.Context, requrl string, postData, r
140144
return err
141145
}
142146

143-
defer resp.Body.Close()
147+
defer func() {
148+
if err := resp.Body.Close(); err != nil {
149+
logrus.WithError(err).Warn("failed to close response body")
150+
}
151+
}()
144152

145153
if resp.StatusCode != nethttp.StatusOK {
146154
if resp.StatusCode == nethttp.StatusNotFound {

pkg/coordinator/clients/consensus/rpc/eventstream/eventstream.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,13 @@ func (stream *Stream) connect() (r io.ReadCloser, err error) {
158158
}
159159

160160
func (stream *Stream) stream(r io.ReadCloser) {
161-
defer r.Close()
161+
defer func() {
162+
if err := r.Close(); err != nil {
163+
if stream.Logger != nil {
164+
stream.Logger.Printf("failed to close reader: %v", err)
165+
}
166+
}
167+
}()
162168

163169
stream.Ready <- true
164170

pkg/coordinator/clients/execution/rpc/executionapi.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,6 @@ func (ec *ExecutionClient) SendTransaction(ctx context.Context, tx *types.Transa
211211
return ec.ethClient.SendTransaction(reqCtx, tx)
212212
}
213213

214-
//nolint:gocritic // ignore
215214
func (ec *ExecutionClient) GetEthCall(ctx context.Context, msg ethereum.CallMsg, blockNumber *big.Int) ([]byte, error) {
216215
closeFn := ec.enforceConcurrencyLimit(ctx)
217216
if closeFn == nil {

pkg/coordinator/names/validatornames.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,12 @@ func (vn *ValidatorNames) loadFromYaml(fileName string) error {
8181
if err != nil {
8282
return fmt.Errorf("error opening validator names file %v: %v", fileName, err)
8383
}
84-
defer f.Close()
84+
85+
defer func() {
86+
if err := f.Close(); err != nil {
87+
vn.logger.WithError(err).Warn("failed to close file")
88+
}
89+
}()
8590

8691
namesYaml := map[string]string{}
8792
decoder := yaml.NewDecoder(f)
@@ -139,7 +144,11 @@ func (vn *ValidatorNames) loadFromRangesAPI(apiURL string) error {
139144
return fmt.Errorf("could not fetch inventory (%v): %v", getRedactedURL(apiURL), err)
140145
}
141146

142-
defer resp.Body.Close()
147+
defer func() {
148+
if err := resp.Body.Close(); err != nil {
149+
vn.logger.WithError(err).Warn("failed to close response body")
150+
}
151+
}()
143152

144153
if resp.StatusCode != http.StatusOK {
145154
if resp.StatusCode == http.StatusNotFound {

pkg/coordinator/tasks/run_external_tasks/task.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,11 @@ func (t *Task) loadTestConfig(ctx context.Context, testFile string) (*types.Test
202202
return nil, err
203203
}
204204

205-
defer resp.Body.Close()
205+
defer func() {
206+
if err := resp.Body.Close(); err != nil {
207+
t.logger.WithError(err).Warn("failed to close response body")
208+
}
209+
}()
206210

207211
if resp.StatusCode != http.StatusOK {
208212
return nil, fmt.Errorf("error loading test config from url: %v, result: %v %v", testFile, resp.StatusCode, resp.Status)
@@ -215,7 +219,11 @@ func (t *Task) loadTestConfig(ctx context.Context, testFile string) (*types.Test
215219
return nil, fmt.Errorf("error loading test config from file %v: %w", testFile, err)
216220
}
217221

218-
defer f.Close()
222+
defer func() {
223+
if err := f.Close(); err != nil {
224+
t.logger.WithError(err).Warn("failed to close file")
225+
}
226+
}()
219227

220228
reader = f
221229
}

pkg/coordinator/tasks/run_shell/task.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,9 @@ func (t *Task) Execute(ctx context.Context) error {
137137
return err
138138
}
139139

140-
stdin.Close()
140+
if err := stdin.Close(); err != nil {
141+
t.logger.WithError(err).Warn("failed to close stdin")
142+
}
141143

142144
// wait for process & output streams
143145
var execErr error

pkg/coordinator/test/descriptor.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"time"
1111

1212
"github.com/ethpandaops/assertoor/pkg/coordinator/types"
13+
"github.com/sirupsen/logrus"
1314
"gopkg.in/yaml.v3"
1415
)
1516

@@ -102,7 +103,11 @@ func LoadExternalTestConfig(ctx context.Context, globalVars types.Variables, ext
102103
return nil, nil, err
103104
}
104105

105-
defer resp.Body.Close()
106+
defer func() {
107+
if err := resp.Body.Close(); err != nil {
108+
logrus.WithError(err).Warn("failed to close response body")
109+
}
110+
}()
106111

107112
if resp.StatusCode != http.StatusOK {
108113
return nil, nil, fmt.Errorf("error loading test config from url: %v, result: %v %v", extTestCfg.File, resp.StatusCode, resp.Status)
@@ -115,7 +120,11 @@ func LoadExternalTestConfig(ctx context.Context, globalVars types.Variables, ext
115120
return nil, nil, fmt.Errorf("error loading test config from file %v: %w", extTestCfg.File, err)
116121
}
117122

118-
defer f.Close()
123+
defer func() {
124+
if err := f.Close(); err != nil {
125+
logrus.WithError(err).Warn("failed to close file")
126+
}
127+
}()
119128

120129
reader = f
121130
}

pkg/coordinator/vars/variables.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,6 @@ func (v *Variables) getGeneralizedVarsMap() (map[string]any, error) {
231231
return varsMap, nil
232232
}
233233

234-
//nolint:gocritic // ignore
235234
func (v *Variables) ResolveQuery(queryStr string) (interface{}, bool, error) {
236235
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
237236
defer cancel()

pkg/coordinator/wallet/blobtx/blobtx.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/ethereum/go-ethereum/core/types"
1515
"github.com/ethereum/go-ethereum/crypto/kzg4844"
1616
"github.com/ethereum/go-ethereum/params"
17+
"github.com/sirupsen/logrus"
1718
)
1819

1920
func GenerateBlobSidecar(blobRefs []string, txIdx, replacementIdx uint64) ([]common.Hash, *types.BlobTxSidecar, error) {
@@ -129,7 +130,12 @@ func loadURLRef(url string) ([]byte, error) {
129130
if err != nil {
130131
return nil, err
131132
}
132-
defer response.Body.Close()
133+
134+
defer func() {
135+
if err := response.Body.Close(); err != nil {
136+
logrus.WithError(err).Warn("failed to close response body")
137+
}
138+
}()
133139

134140
if response.StatusCode != 200 {
135141
return nil, fmt.Errorf("received http error: %v", response.Status)

pkg/coordinator/wallet/manager.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,6 @@ func (manager *Manager) loadBlockReceipts(block *execution.Block) []*ethtypes.Re
176176
client := clients[cliIdx]
177177

178178
reqCtx, reqCtxCancel := context.WithTimeout(context.Background(), 5*time.Second)
179-
180-
//nolint:gocritic // ignore
181179
defer reqCtxCancel()
182180

183181
receipts, err := client.GetRPCClient().GetBlockReceipts(reqCtx, block.Hash)

0 commit comments

Comments
 (0)