Skip to content

Commit

Permalink
feat: enable more golanglint linters (#2334)
Browse files Browse the repository at this point in the history
  • Loading branch information
cgrinds authored Aug 29, 2023
1 parent 0ef91a6 commit 09beef2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ linters:
- exhaustive
- exportloopref
- gocheckcompilerdirectives
- gocritic
- gosec
- gosimple
- govet
Expand Down
18 changes: 11 additions & 7 deletions cmd/harvest/harvest.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,14 +449,11 @@ func startPoller(pollerName string, promPort int, opts *options) {
// Redirect standard file descriptors to /dev/null
devNull, err := os.OpenFile(os.DevNull, os.O_RDWR, 0)
if err != nil {
fmt.Println("Error opening /dev/null:", err)
fmt.Println("Error opening /dev/null: ", err)
os.Exit(1)
}
defer func() {
if err := devNull.Close(); err != nil {
fmt.Println("Error closing /dev/null:", err)
}
}()

defer closeDevNull(devNull)

cmd.Stdin = devNull
cmd.Stdout = devNull
Expand All @@ -465,7 +462,14 @@ func startPoller(pollerName string, promPort int, opts *options) {
// Start the poller process in the background
if err := cmd.Start(); err != nil {
fmt.Println(err)
os.Exit(1)
closeDevNull(devNull) // os.Exit means closeDevNull will not run so call directly
os.Exit(1) //nolint:gocritic
}
}

func closeDevNull(devNull *os.File) {
if err := devNull.Close(); err != nil {
fmt.Println("Error closing /dev/null: ", err)
}
}

Expand Down

0 comments on commit 09beef2

Please sign in to comment.