mirror of
https://github.com/kubernetes/node-problem-detector.git
synced 2026-08-19 04:06:24 +00:00
enabled and fixed the errcheck linter rule
This commit is contained in:
+8
-2
@@ -19,6 +19,8 @@ package util
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"k8s.io/klog/v2"
|
||||
)
|
||||
|
||||
// ReturnHTTPJson generates json http response.
|
||||
@@ -30,11 +32,15 @@ func ReturnHTTPJson(w http.ResponseWriter, object interface{}) {
|
||||
}
|
||||
w.Header().Set("Content-type", "application/json")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write(data)
|
||||
if _, err := w.Write(data); err != nil {
|
||||
klog.Errorf("Failed to write http response: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// ReturnHTTPError generates error http response.
|
||||
func ReturnHTTPError(w http.ResponseWriter, err error) {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.Write([]byte(err.Error()))
|
||||
if _, err := w.Write([]byte(err.Error())); err != nil {
|
||||
klog.Errorf("Failed to write http error response: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -232,7 +232,9 @@ func TestFakeInt64Metric(t *testing.T) {
|
||||
metric := NewFakeInt64Metric(test.metricName, test.aggregation, test.tagNames)
|
||||
|
||||
for _, record := range test.records {
|
||||
metric.Record(record.tags, record.measurement)
|
||||
if err := metric.Record(record.tags, record.measurement); err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
gotMetrics := metric.ListMetrics()
|
||||
|
||||
@@ -72,7 +72,9 @@ func NewFloat64Metric(metricID MetricID, viewName string, description string, un
|
||||
Aggregation: aggregationMethod,
|
||||
TagKeys: tagKeys,
|
||||
}
|
||||
view.Register(newView)
|
||||
if err := view.Register(newView); err != nil {
|
||||
return nil, fmt.Errorf("failed to register view for metric %q: %v", viewName, err)
|
||||
}
|
||||
|
||||
metric := Float64Metric{viewName, measure}
|
||||
return &metric, nil
|
||||
|
||||
@@ -72,7 +72,9 @@ func NewInt64Metric(metricID MetricID, viewName string, description string, unit
|
||||
Aggregation: aggregationMethod,
|
||||
TagKeys: tagKeys,
|
||||
}
|
||||
view.Register(newView)
|
||||
if err := view.Register(newView); err != nil {
|
||||
return nil, fmt.Errorf("failed to register view for metric %q: %v", viewName, err)
|
||||
}
|
||||
|
||||
metric := Int64Metric{viewName, measure}
|
||||
return &metric, nil
|
||||
|
||||
@@ -16,6 +16,8 @@ package system
|
||||
import (
|
||||
"bufio"
|
||||
"os"
|
||||
|
||||
"k8s.io/klog/v2"
|
||||
)
|
||||
|
||||
// ReadFileIntoLines reads contents from a file and returns lines.
|
||||
@@ -24,7 +26,11 @@ func ReadFileIntoLines(filename string) ([]string, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer file.Close()
|
||||
defer func() {
|
||||
if err := file.Close(); err != nil {
|
||||
klog.Errorf("Failed to close file %s: %v", filename, err)
|
||||
}
|
||||
}()
|
||||
|
||||
var result []string
|
||||
s := bufio.NewScanner(file)
|
||||
|
||||
Reference in New Issue
Block a user