Skip to content

Commit 4f5fd63

Browse files
noushavandijkrichpoirier
authored andcommitted
Fix infinite recursion on unknown Level.String()
Using `%q` in the error string causes `MarshalText` to recurse (by calling String()).
1 parent cdb2f38 commit 4f5fd63

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

logrus.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func (level Level) MarshalText() ([]byte, error) {
7474
return []byte("panic"), nil
7575
}
7676

77-
return nil, fmt.Errorf("not a valid lorus level %q", level)
77+
return nil, fmt.Errorf("not a valid logrus level %d", level)
7878
}
7979

8080
// A constant exposing all logging levels

logrus_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,13 @@ func TestParseLevel(t *testing.T) {
521521
assert.Equal(t, "not a valid logrus Level: \"invalid\"", err.Error())
522522
}
523523

524+
func TestLevelString(t *testing.T) {
525+
var loggerlevel Level
526+
loggerlevel = 32000
527+
528+
_ = loggerlevel.String()
529+
}
530+
524531
func TestGetSetLevelRace(t *testing.T) {
525532
wg := sync.WaitGroup{}
526533
for i := 0; i < 100; i++ {

0 commit comments

Comments
 (0)