Skip to content

Commit 7bb6365

Browse files
committed
httperr.DontLog does not wrap nil error
1 parent cd535ea commit 7bb6365

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

httperr/wrap.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,27 @@ import (
77

88
// DontLog wraps the passed error
99
// so that ShouldLog returns false.
10+
// A nil error won't be wrapped but returned as nil.
1011
//
11-
// httperr.ShouldLog(httperr.BadRequest) == true
12-
// httperr.ShouldLog(httperr.DontLog(httperr.BadRequest)) == false
12+
// httperr.ShouldLog(httperr.BadRequest) == true
13+
// httperr.ShouldLog(httperr.DontLog(httperr.BadRequest)) == false
1314
func DontLog(err error) error {
15+
if err == nil {
16+
return nil
17+
}
1418
return errDontLog{err}
1519
}
1620

1721
// ShouldLog checks if the passed error
1822
// has been wrapped with DontLog.
23+
// A nil error results in false.
1924
//
20-
// httperr.ShouldLog(httperr.BadRequest) == true
21-
// httperr.ShouldLog(httperr.DontLog(httperr.BadRequest)) == false
25+
// httperr.ShouldLog(httperr.BadRequest) == true
26+
// httperr.ShouldLog(httperr.DontLog(httperr.BadRequest)) == false
2227
func ShouldLog(err error) bool {
28+
if err == nil {
29+
return false
30+
}
2331
var dontLog errDontLog
2432
return !errors.As(err, &dontLog)
2533
}

0 commit comments

Comments
 (0)