Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some errcheck errors #2881

Merged
merged 9 commits into from
May 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion component/componenttest/shutdown_verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func verifyTracesProcessorDoesntProduceAfterShutdown(t *testing.T, factory compo
// Send some traces to the processor.
const generatedCount = 10
for i := 0; i < generatedCount; i++ {
processor.ConsumeTraces(context.Background(), testdata.GenerateTraceDataOneSpan())
require.NoError(t, processor.ConsumeTraces(context.Background(), testdata.GenerateTraceDataOneSpan()))
}

// Now shutdown the processor.
Expand Down
2 changes: 1 addition & 1 deletion exporter/otlphttpexporter/otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func (e *exporterImp) export(ctx context.Context, url string, request []byte) er

defer func() {
// Discard any remaining response body when we are done reading.
io.CopyN(ioutil.Discard, resp.Body, maxHTTPResponseReadBytes)
io.CopyN(ioutil.Discard, resp.Body, maxHTTPResponseReadBytes) // nolint:errcheck
resp.Body.Close()
bogdandrutu marked this conversation as resolved.
Show resolved Hide resolved
}()

Expand Down
2 changes: 1 addition & 1 deletion processor/processorhelper/hasher.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func sha1Hasher(attr pdata.AttributeValue) {
if len(val) > 0 {
// #nosec
h := sha1.New()
h.Write(val)
h.Write(val) // nolint: errcheck
val = h.Sum(nil)
hashedBytes := make([]byte, hex.EncodedLen(len(val)))
hex.Encode(hashedBytes, val)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ func appendSystemSpecificProcessesMetrics(metrics pdata.MetricSlice, startIndex

metrics.Resize(startIndex + unixMetricsLen)
initializeProcessesCountMetric(metrics.At(startIndex+0), now, misc)
appendUnixSystemSpecificProcessesMetrics(metrics, startIndex+1, now, misc)
if err = appendUnixSystemSpecificProcessesMetrics(metrics, startIndex+1, now, misc); err != nil {
return err
}
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion receiver/kafkareceiver/kafka_receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (c *kafkaConsumer) Start(context.Context, component.Host) error {
nextConsumer: c.nextConsumer,
ready: make(chan bool),
}
go c.consumeLoop(ctx, consumerGroup)
go c.consumeLoop(ctx, consumerGroup) // nolint:errcheck
<-consumerGroup.ready
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion receiver/otlpreceiver/otlphttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,5 @@ func errorHandler(w http.ResponseWriter, r *http.Request, errMsg string, statusC

w.Header().Set("Content-Type", contentType)
w.WriteHeader(statusCode)
w.Write(msg)
w.Write(msg) // nolint:errcheck
}
2 changes: 1 addition & 1 deletion receiver/zipkinreceiver/trace_receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func (zr *ZipkinReceiver) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if consumerErr != nil {
// Transient error, due to some internal condition.
w.WriteHeader(http.StatusInternalServerError)
w.Write(errNextConsumerRespBody)
w.Write(errNextConsumerRespBody) // nolint:errcheck
return
}

Expand Down
6 changes: 3 additions & 3 deletions service/zpages.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (srv *service) RegisterZPages(mux *http.ServeMux, pathPrefix string) {
}

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

func (srv *service) handlePipelinezRequest(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
r.ParseForm() // nolint:errcheck
w.Header().Set("Content-Type", "text/html; charset=utf-8")
pipelineName := r.Form.Get(zPipelineName)
componentName := r.Form.Get(zComponentName)
Expand Down Expand Up @@ -103,7 +103,7 @@ func (srv *service) getPipelinesSummaryTableData() zpages.SummaryPipelinesTableD
}

func handleExtensionzRequest(host component.Host, w http.ResponseWriter, r *http.Request) {
r.ParseForm()
r.ParseForm() // nolint:errcheck
w.Header().Set("Content-Type", "text/html; charset=utf-8")
extensionName := r.Form.Get(zExtensionName)
zpages.WriteHTMLHeader(w, zpages.HeaderData{Title: "Extensions"})
Expand Down
4 changes: 3 additions & 1 deletion testbed/testbed/child_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,9 @@ func (cp *ChildProcess) WatchResourceConsumption() error {
cp.fetchCPUUsage()

if err := cp.checkAllowedResourceUsage(); err != nil {
cp.Stop()
if _, errStop := cp.Stop(); errStop != nil {
log.Printf("Failed to stop child process: %v", err)
}
return err
}

Expand Down
5 changes: 3 additions & 2 deletions testbed/testbed/mock_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@ func (mb *MockBackend) Stop() {
log.Printf("Stopping mock backend...")

mb.logFile.Close()
mb.receiver.Stop()

if err := mb.receiver.Stop(); err != nil {
log.Printf("Failed to stop receiver: %v", err)
}
// Print stats.
log.Printf("Stopped backend. %s", mb.GetStats())
})
Expand Down
12 changes: 8 additions & 4 deletions testbed/testbed/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,13 @@ func (r *PerformanceResults) Init(resultsDir string) {
r.perTestResults = []*PerformanceTestResult{}

// Create resultsSummary file
os.MkdirAll(resultsDir, os.FileMode(0755))
if err := os.MkdirAll(resultsDir, os.FileMode(0755)); err != nil {
log.Fatal(err)
}
var err error
r.resultsFile, err = os.Create(path.Join(r.resultsDir, "TESTRESULTS.md"))
if err != nil {
log.Fatalf(err.Error())
log.Fatal(err)
}

// Write the header
Expand Down Expand Up @@ -145,11 +147,13 @@ func (r *CorrectnessResults) Init(resultsDir string) {
r.perTestResults = []*CorrectnessTestResult{}

// Create resultsSummary file
os.MkdirAll(resultsDir, os.FileMode(0755))
if err := os.MkdirAll(resultsDir, os.FileMode(0755)); err != nil {
log.Fatal(err)
}
var err error
r.resultsFile, err = os.Create(path.Join(r.resultsDir, "CORRECTNESSRESULTS.md"))
if err != nil {
log.Fatalf(err.Error())
log.Fatal(err)
}

// Write the header
Expand Down
4 changes: 3 additions & 1 deletion testbed/testbed/test_case.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,9 @@ func (tc *TestCase) StartAgent(args ...string) {

// StopAgent stops agent process.
func (tc *TestCase) StopAgent() {
tc.agentProc.Stop()
if _, err := tc.agentProc.Stop(); err != nil {
tc.indicateError(err)
}
}

// StartLoad starts the load generator and redirects its standard output and standard error
Expand Down