Skip to content

Commit

Permalink
Fix errcheck linter for most of non-test files
Browse files Browse the repository at this point in the history
Add handling errors where it was missing
  • Loading branch information
panslava committed Sep 14, 2022
1 parent 4a6258b commit ba263af
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 24 deletions.
7 changes: 0 additions & 7 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,5 @@ issues:
linters-settings:
errcheck:
exclude-functions:
- fmt.Fprintf
- fmt.Fprint
- (net/http.ResponseWriter).Write
- (*net/http.Server).Shutdown
- (*flag.FlagSet).Parse
- (*os.File).Close
- (io.Closer).Close
- (flag.Value).Set
- k8s.io/apimachinery/pkg/util/wait.PollUntil
10 changes: 8 additions & 2 deletions cmd/404-server-with-metrics/server-with-metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,12 @@ func gracefulShutdown(s *server) {
klog.Infof("received /shutdown message, doing a graceful shutdown of http and metrics servers: \n")
}

s.httpServer.Shutdown(context.Background())
s.metricsServer.Shutdown(context.Background())
err := s.httpServer.Shutdown(context.Background())
if err != nil {
klog.Errorf("Error shutting down httpServer: %v", err)
}
err = s.metricsServer.Shutdown(context.Background())
if err != nil {
klog.Errorf("Error shutting down metricsServer: %v", err)
}
}
23 changes: 19 additions & 4 deletions cmd/echo/app/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ func RunHTTPServer(ctx context.Context) {
}

<-ctx.Done()
server.Shutdown(ctx)
err = server.Shutdown(ctx)
if err != nil {
klog.Infof("Error on server shutdown %v", err)
}
}()

go func() {
Expand All @@ -82,15 +85,23 @@ func RunHTTPServer(ctx context.Context) {
}

<-ctx.Done()
server.Shutdown(ctx)

err = server.Shutdown(ctx)
if err != nil {
klog.Errorf("Error on server shutdown %v", err)
}
}()

<-ctx.Done()
}

func healthCheck(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte("health: OK"))
_, err := w.Write([]byte("health: OK"))
if err != nil {
klog.Errorf("Error writing bytes: %v, UserAgent: %v, RemoteAddr: %v", err, r.UserAgent(), r.RemoteAddr)
return
}
klog.V(3).Infof("healthcheck: %v, %v, %v", time.Now(), r.UserAgent(), r.RemoteAddr)
}

Expand Down Expand Up @@ -123,7 +134,11 @@ func echo(w http.ResponseWriter, r *http.Request) {
return
}

w.Write(processedData)
_, err = w.Write(processedData)
if err != nil {
klog.Errorf("Error writing data: %v, UserAgent: %v, RemoteAddr: %v", err, r.UserAgent(), r.RemoteAddr)
return
}
klog.V(3).Infof("echo: %v, %v, %v", time.Now(), r.UserAgent(), r.RemoteAddr)
}

Expand Down
12 changes: 5 additions & 7 deletions cmd/fuzzer/fuzzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,7 @@ import (
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
_ "k8s.io/client-go/plugin/pkg/client/auth/oidc"
"k8s.io/ingress-gce/cmd/fuzzer/app"
)

var (
kubeconfig *string
ingressNamespace *string
ingressName *string
"k8s.io/klog/v2"
)

func main() {
Expand All @@ -43,7 +38,10 @@ func main() {

switch os.Args[1] {
case "validate":
app.ValidateFlagSet.Parse(os.Args[2:])
err := app.ValidateFlagSet.Parse(os.Args[2:])
if err != nil {
klog.Errorf("app.ValidateFlagSet.Parse(%v) returned error: %v", os.Args[2:], err)
}
default:
flag.Usage()
os.Exit(1)
Expand Down
15 changes: 12 additions & 3 deletions cmd/glbc/app/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,17 @@ func healthCheckHandler(checker func() context.HealthCheckResults) http.HandlerF
}

if s.Len() == 0 {
w.Write([]byte("OK - no running controllers"))
_, err := w.Write([]byte("OK - no running controllers"))
if err != nil {
klog.Errorf("Error writing bytes: %v", err)
}
return
}

w.Write([]byte(s.String()))
_, err := w.Write([]byte(s.String()))
if err != nil {
klog.Errorf("Error writing bytes: %v", err)
}
return
}
}
Expand Down Expand Up @@ -129,8 +135,11 @@ func putFlag(w http.ResponseWriter, r *http.Request) {
}

func setVerbosity(v string) {
flag.Lookup("v").Value.Set(v)
klog.V(0).Infof("Setting verbosity level to %q", v)
err := flag.Lookup("v").Value.Set(v)
if err != nil {
klog.Errorf("flag.Lookup(\"v\").Value.Set(%v) returned error: %v", v, err)
}
}

func getFlagPage(w http.ResponseWriter, r *http.Request) {
Expand Down
5 changes: 4 additions & 1 deletion cmd/workload-daemon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ func main() {
outputHelp()
return
}
cmdSet.Parse(os.Args[2:])
err := cmdSet.Parse(os.Args[2:])
if err != nil {
klog.Errorf("Error parsing os.Args: %v", err)
}
if *provider != "gce" {
klog.Fatalf("Current implementation only supports gce provider.")
}
Expand Down

0 comments on commit ba263af

Please sign in to comment.