Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enable more golanglint linters #2334

Merged
merged 1 commit into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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