Skip to content

Commit ce984cd

Browse files
authored
lint: errcheck (#3912)
1 parent 2860dca commit ce984cd

File tree

5 files changed

+24
-13
lines changed

5 files changed

+24
-13
lines changed

.golangci.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,6 @@ linters:
119119
# See https://github.com/kisielk/errcheck#excluding-functions for details.
120120
exclude-functions:
121121
- (*bytes.Buffer).ReadFrom # TODO
122-
- (net/http.ResponseWriter).Write # TODO
123-
- (*os/exec.Cmd).Wait
124122
- syscall.FreeLibrary
125123
- golang.org/x/sys/windows.CloseHandle
126124
- golang.org/x/sys/windows.ResetEvent

cmd/crowdsec-cli/clinotifications/notifications.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ func (cli *cliNotifications) newTestCmd() *cobra.Command {
360360

361361
// time.Sleep(2 * time.Second) // There's no mechanism to ensure notification has been sent
362362
pluginTomb.Kill(errors.New("terminating"))
363-
pluginTomb.Wait()
363+
_ = pluginTomb.Wait()
364364

365365
return nil
366366
},
@@ -478,7 +478,7 @@ cscli notifications reinject <alert_id> -a '{"remediation": true,"scenario":"not
478478
}
479479
// time.Sleep(2 * time.Second) // There's no mechanism to ensure notification has been sent
480480
pluginTomb.Kill(errors.New("terminating"))
481-
pluginTomb.Wait()
481+
_ = pluginTomb.Wait()
482482

483483
return nil
484484
},

pkg/acquisition/modules/file/file_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ mode: tail
595595

596596
// Cleanup
597597
tomb.Kill(nil)
598-
tomb.Wait()
598+
require.NoError(t, tomb.Wait())
599599
}
600600

601601
func TestFileResurrectionViaPolling(t *testing.T) {
@@ -645,5 +645,5 @@ mode: tail
645645

646646
// Cleanup
647647
tomb.Kill(nil)
648-
tomb.Wait()
648+
require.NoError(t, tomb.Wait())
649649
}

pkg/acquisition/modules/http/http.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,11 @@ func (h *HTTPSource) GetMode() string {
174174
return h.Config.Mode
175175
}
176176

177-
func (h *HTTPSource) GetName() string {
177+
func (*HTTPSource) GetName() string {
178178
return dataSourceName
179179
}
180180

181-
func (h *HTTPSource) CanRun() error {
181+
func (*HTTPSource) CanRun() error {
182182
return nil
183183
}
184184

@@ -269,6 +269,7 @@ func (h *HTTPSource) processRequest(w http.ResponseWriter, r *http.Request, hc *
269269

270270
if h.logger.Logger.IsLevelEnabled(log.TraceLevel) {
271271
h.logger.Tracef("processing request from '%s' with method '%s' and path '%s'", r.RemoteAddr, r.Method, r.URL.Path)
272+
272273
bodyContent, err := httputil.DumpRequest(r, true)
273274
if err != nil {
274275
h.logger.Errorf("failed to dump request: %s", err)
@@ -350,7 +351,11 @@ func (h *HTTPSource) RunServer(ctx context.Context, out chan types.Event, t *tom
350351
case http.MethodGet, http.MethodHead: // Return a 200 if the auth was successful
351352
h.logger.Infof("successful %s request from '%s'", r.Method, r.RemoteAddr)
352353
w.WriteHeader(http.StatusOK)
353-
w.Write([]byte("OK"))
354+
355+
if _, err := w.Write([]byte("OK")); err != nil {
356+
h.logger.Errorf("failed to write response: %v", err)
357+
}
358+
354359
return
355360
case http.MethodPost: // POST is handled below
356361
default:
@@ -382,7 +387,9 @@ func (h *HTTPSource) RunServer(ctx context.Context, out chan types.Event, t *tom
382387
w.WriteHeader(http.StatusOK)
383388
}
384389

385-
w.Write([]byte("OK"))
390+
if _, err := w.Write([]byte("OK")); err != nil {
391+
h.logger.Errorf("failed to write response: %v", err)
392+
}
386393
})
387394

388395
h.Server = &http.Server{
@@ -417,12 +424,15 @@ func (h *HTTPSource) RunServer(ctx context.Context, out chan types.Event, t *tom
417424
}
418425

419426
defer trace.CatchPanic("crowdsec/acquis/http/server/unix")
427+
420428
h.logger.Infof("creating unix socket on %s", h.Config.ListenSocket)
421429
_ = os.Remove(h.Config.ListenSocket)
430+
422431
listener, err := listenConfig.Listen(ctx, "unix", h.Config.ListenSocket)
423432
if err != nil {
424433
return csnet.WrapSockErr(err, h.Config.ListenSocket)
425434
}
435+
426436
if h.Config.TLS != nil {
427437
err := h.Server.ServeTLS(listener, h.Config.TLS.ServerCert, h.Config.TLS.ServerKey)
428438
if err != nil && err != http.ErrServerClosed {

pkg/acquisition/modules/journalctl/journalctl.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,15 @@ func (j *JournalCtlSource) runJournalCtl(ctx context.Context, out chan types.Eve
9999

100100
if stdoutscanner == nil {
101101
cancel()
102-
cmd.Wait()
102+
_ = cmd.Wait()
103103
return errors.New("failed to create stdout scanner")
104104
}
105105

106106
stderrScanner := bufio.NewScanner(stderr)
107107

108108
if stderrScanner == nil {
109109
cancel()
110-
cmd.Wait()
110+
_ = cmd.Wait()
111111
return errors.New("failed to create stderr scanner")
112112
}
113113

@@ -125,7 +125,10 @@ func (j *JournalCtlSource) runJournalCtl(ctx context.Context, out chan types.Eve
125125
case <-t.Dying():
126126
logger.Infof("journalctl datasource %s stopping", j.src)
127127
cancel()
128-
cmd.Wait() // avoid zombie process
128+
// avoid zombie process
129+
if waitErr := cmd.Wait(); waitErr != nil {
130+
j.logger.Debugf("journalctl exited after cancel: %v", waitErr)
131+
}
129132

130133
return nil
131134
case stdoutLine := <-stdoutChan:

0 commit comments

Comments
 (0)