Skip to content

False positive G307: Deferring unsafe method "Close" on type "*os.File" (gosec) linting error #123

@atc0005

Description

@atc0005
Owner

False-positive error surfaced from an upgraded golangci-lint:

internal/config/file.go:35:2: G307: Deferring unsafe method "Close" on type "*os.File" (gosec)
	defer func() {
		if err := fh.Close(); err != nil {
			// Ignore "file already closed" errors
			if !errors.Is(err, os.ErrClosed) {
				log.Errorf(
					"loadConfigFile: failed to close file %q: %s",
					configFile,
					err.Error(),
				)
			}
		}
	}()
make: *** [Makefile:149: linting] Error 1
Error: Process completed with exit code 2.

Same problem as noted on atc0005/check-mail#234.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinglinting

Projects

No projects

Relationships

None yet

    Development

    Participants

    @atc0005

    Issue actions

      False positive `G307: Deferring unsafe method "Close" on type "*os.File" (gosec)` linting error · Issue #123 · atc0005/mysql2sqlite