Browse Source

Fix infinite recursion on unknown Level.String()

Using `%q` in the error string causes `MarshalText` to recurse (by calling String()).
tags/v1.4.0
noushavandijk 9 months ago
parent
commit
4f5fd631f1
2 changed files with 8 additions and 1 deletions
  1. 1
    1
      logrus.go
  2. 7
    0
      logrus_test.go

+ 1
- 1
logrus.go View File

@@ -74,7 +74,7 @@ func (level Level) MarshalText() ([]byte, error) {
74 74
 		return []byte("panic"), nil
75 75
 	}
76 76
 
77
-	return nil, fmt.Errorf("not a valid lorus level %q", level)
77
+	return nil, fmt.Errorf("not a valid logrus level %d", level)
78 78
 }
79 79
 
80 80
 // A constant exposing all logging levels

+ 7
- 0
logrus_test.go View File

@@ -521,6 +521,13 @@ func TestParseLevel(t *testing.T) {
521 521
 	assert.Equal(t, "not a valid logrus Level: \"invalid\"", err.Error())
522 522
 }
523 523
 
524
+func TestLevelString(t *testing.T) {
525
+	var loggerlevel Level
526
+	loggerlevel = 32000
527
+
528
+	_ = loggerlevel.String()
529
+}
530
+
524 531
 func TestGetSetLevelRace(t *testing.T) {
525 532
 	wg := sync.WaitGroup{}
526 533
 	for i := 0; i < 100; i++ {

Loading…
Cancel
Save