Skip to content

Commit

Permalink
Handle error properly on file close
Browse files Browse the repository at this point in the history
  • Loading branch information
swi-jared committed Jul 30, 2024
1 parent e5de4ad commit fae6657
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion internal/host/k8s/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit fae6657

Please sign in to comment.