Fix G307 warning: Deferring unsafe method "Close" on type "*os.File" (#1154)

* fix: check potential error from file.Close

* fix(detect): use existing logger
This commit is contained in:
Richard Gomez authored and GitHub committed 2023-04-19 11:56:08 -05:00
1 parent bd8b145bea
commit 81cf30855c
1 file changed
+6 -1
+6 -1
View File
@@ -154,7 +154,12 @@ func (d *Detector) AddGitleaksIgnore(gitleaksIgnorePath string) error {
return err
}
defer file.Close()
// https://github.com/securego/gosec/issues/512
defer func() {
if err := file.Close(); err != nil {
log.Warn().Msgf("Error closing .gitleaksignore file: %s\n", err)
}
}()
scanner := bufio.NewScanner(file)
for scanner.Scan() {