Skip to content

Commit 4d408e9

Browse files
committed
fix: add os.Exit and log.Fatal.* to forbidigo
We should never panic in the library
1 parent 273354c commit 4d408e9

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

.golangci.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ linters:
9393
forbid:
9494
- pattern: ^(fmt\.Print(|f|ln)|print|println)$
9595
- pattern: ^panic$
96+
- pattern: ^log\.Fatal.*$
97+
- pattern: ^os\.Exit$
9698

9799
exclusions:
98100
generated: lax

internal/netutil.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package netutil
22

33
import (
44
"bytes"
5+
"fmt"
56
"io"
6-
"log"
77
"net/url"
88
"os"
99
"path"
@@ -43,7 +43,7 @@ func DownloadTmpFile(url *url.URL, headers map[string]string) (string, error) {
4343
// Create a temp dir
4444
tmpdir, err := os.MkdirTemp("", "publiccode.yml-parser-go")
4545
if err != nil {
46-
log.Fatal(err)
46+
return "", fmt.Errorf("creating temp dir: %w", err)
4747
}
4848

4949
// Download the file in the temp dir.

validators/validator.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ func RegisterLocalErrorMessages(v *validator.Validate, trans ut.Translator) erro
205205
func registrationFunc(tag string, translation string, override bool) validator.RegisterTranslationsFunc {
206206
return func(ut ut.Translator) error {
207207
if err := ut.Add(tag, translation, override); err != nil {
208+
//nolint:forbidigo // Programming error caught at runtime, it's right to panic
208209
log.Fatalf("Error %s", err.Error())
209210

210211
return err

0 commit comments

Comments
 (0)