enabled and fixed the errcheck linter rule

This commit is contained in:
Sergey Kanzhelev
2025-09-10 21:45:46 +00:00
parent 2fc1699725
commit 0ce333bbc5
27 changed files with 315 additions and 106 deletions
+8 -2
View File
@@ -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)
}
}
+3 -1
View File
@@ -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()
+3 -1
View File
@@ -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
+3 -1
View File
@@ -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
+7 -1
View File
@@ -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)