Skip to content

Commit 29b576e

Browse files
authored
Fix some errcheck errors (#2881)
* Check testbed errors * Check some more errors * Empty commit to retrigger CI * Address comments on hostmetricsreceiver * Rewrite some errchecking code * Inline ifs * Inline ifs and change log.Fatalf + Error() calls by log.Fatal
1 parent 4976c05 commit 29b576e

File tree

12 files changed

+29
-18
lines changed

12 files changed

+29
-18
lines changed

component/componenttest/shutdown_verifier.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func verifyTracesProcessorDoesntProduceAfterShutdown(t *testing.T, factory compo
5050
// Send some traces to the processor.
5151
const generatedCount = 10
5252
for i := 0; i < generatedCount; i++ {
53-
processor.ConsumeTraces(context.Background(), testdata.GenerateTraceDataOneSpan())
53+
require.NoError(t, processor.ConsumeTraces(context.Background(), testdata.GenerateTraceDataOneSpan()))
5454
}
5555

5656
// Now shutdown the processor.

exporter/otlphttpexporter/otlp.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func (e *exporter) export(ctx context.Context, url string, request []byte) error
126126

127127
defer func() {
128128
// Discard any remaining response body when we are done reading.
129-
io.CopyN(ioutil.Discard, resp.Body, maxHTTPResponseReadBytes)
129+
io.CopyN(ioutil.Discard, resp.Body, maxHTTPResponseReadBytes) // nolint:errcheck
130130
resp.Body.Close()
131131
}()
132132

processor/processorhelper/hasher.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func sha1Hasher(attr pdata.AttributeValue) {
6161
if len(val) > 0 {
6262
// #nosec
6363
h := sha1.New()
64-
h.Write(val)
64+
h.Write(val) // nolint: errcheck
6565
val = h.Sum(nil)
6666
hashedBytes := make([]byte, hex.EncodedLen(len(val)))
6767
hex.Encode(hashedBytes, val)

receiver/hostmetricsreceiver/internal/scraper/processesscraper/processes_scraper_unix.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ func appendSystemSpecificProcessesMetrics(metrics pdata.MetricSlice, startIndex
4040

4141
metrics.Resize(startIndex + unixMetricsLen)
4242
initializeProcessesCountMetric(metrics.At(startIndex+0), now, misc)
43-
appendUnixSystemSpecificProcessesMetrics(metrics, startIndex+1, now, misc)
43+
if err = appendUnixSystemSpecificProcessesMetrics(metrics, startIndex+1, now, misc); err != nil {
44+
return err
45+
}
4446
return nil
4547
}
4648

receiver/kafkareceiver/kafka_receiver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func (c *kafkaTracesConsumer) Start(context.Context, component.Host) error {
109109
nextConsumer: c.nextConsumer,
110110
ready: make(chan bool),
111111
}
112-
go c.consumeLoop(ctx, consumerGroup)
112+
go c.consumeLoop(ctx, consumerGroup) // nolint:errcheck
113113
<-consumerGroup.ready
114114
return nil
115115
}

receiver/otlpreceiver/otlphttp.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,5 @@ func errorHandler(w http.ResponseWriter, r *http.Request, errMsg string, statusC
7272

7373
w.Header().Set("Content-Type", contentType)
7474
w.WriteHeader(statusCode)
75-
w.Write(msg)
75+
w.Write(msg) // nolint:errcheck
7676
}

receiver/zipkinreceiver/trace_receiver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ func (zr *ZipkinReceiver) ServeHTTP(w http.ResponseWriter, r *http.Request) {
250250
if consumerErr != nil {
251251
// Transient error, due to some internal condition.
252252
w.WriteHeader(http.StatusInternalServerError)
253-
w.Write(errNextConsumerRespBody)
253+
w.Write(errNextConsumerRespBody) // nolint:errcheck
254254
return
255255
}
256256

service/zpages.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func (srv *service) RegisterZPages(mux *http.ServeMux, pathPrefix string) {
4040
}
4141

4242
func (srv *service) handleServicezRequest(w http.ResponseWriter, r *http.Request) {
43-
r.ParseForm()
43+
r.ParseForm() // nolint:errcheck
4444
w.Header().Set("Content-Type", "text/html; charset=utf-8")
4545
zpages.WriteHTMLHeader(w, zpages.HeaderData{Title: "service"})
4646
zpages.WriteHTMLComponentHeader(w, zpages.ComponentHeaderData{
@@ -58,7 +58,7 @@ func (srv *service) handleServicezRequest(w http.ResponseWriter, r *http.Request
5858
}
5959

6060
func (srv *service) handlePipelinezRequest(w http.ResponseWriter, r *http.Request) {
61-
r.ParseForm()
61+
r.ParseForm() // nolint:errcheck
6262
w.Header().Set("Content-Type", "text/html; charset=utf-8")
6363
pipelineName := r.Form.Get(zPipelineName)
6464
componentName := r.Form.Get(zComponentName)
@@ -116,7 +116,7 @@ func (srv *service) getPipelinesSummaryTableData() zpages.SummaryPipelinesTableD
116116
}
117117

118118
func handleExtensionzRequest(host component.Host, w http.ResponseWriter, r *http.Request) {
119-
r.ParseForm()
119+
r.ParseForm() // nolint:errcheck
120120
w.Header().Set("Content-Type", "text/html; charset=utf-8")
121121
extensionName := r.Form.Get(zExtensionName)
122122
zpages.WriteHTMLHeader(w, zpages.HeaderData{Title: "Extensions"})

testbed/testbed/child_process.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,9 @@ func (cp *ChildProcess) WatchResourceConsumption() error {
375375
cp.fetchCPUUsage()
376376

377377
if err := cp.checkAllowedResourceUsage(); err != nil {
378-
cp.Stop()
378+
if _, errStop := cp.Stop(); errStop != nil {
379+
log.Printf("Failed to stop child process: %v", err)
380+
}
379381
return err
380382
}
381383

testbed/testbed/mock_backend.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,9 @@ func (mb *MockBackend) Stop() {
100100
log.Printf("Stopping mock backend...")
101101

102102
mb.logFile.Close()
103-
mb.receiver.Stop()
104-
103+
if err := mb.receiver.Stop(); err != nil {
104+
log.Printf("Failed to stop receiver: %v", err)
105+
}
105106
// Print stats.
106107
log.Printf("Stopped backend. %s", mb.GetStats())
107108
})

0 commit comments

Comments
 (0)