From fae665705694993ef47d15de83debb7f96f7bd3f Mon Sep 17 00:00:00 2001 From: Jared Harper Date: Tue, 30 Jul 2024 16:39:24 -0700 Subject: [PATCH] Handle error properly on file close --- internal/host/k8s/k8s.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/internal/host/k8s/k8s.go b/internal/host/k8s/k8s.go index 952aa520..f92c2ff8 100644 --- a/internal/host/k8s/k8s.go +++ b/internal/host/k8s/k8s.go @@ -169,10 +169,14 @@ func getPodUidFromFile(fn string) (string, error) { func getPodUidFromProc(fn string) (string, error) { f, err := os.Open(fn) - defer f.Close() if err != nil { return "", err } + defer func() { + if err := f.Close(); err != nil { + log.Warningf("Could not close file: %s", err) + } + }() scanner := bufio.NewScanner(f) for scanner.Scan() { line := scanner.Text()