Skip to content

Commit 9c7cd44

Browse files
committed
Fixed regression in text formatter
1 parent 137c325 commit 9c7cd44

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

common/formatter/print_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,14 @@ func ExamplePrint() {
6262
func ExamplePrint_alternative() {
6363
formatter.SetFormatter("text")
6464
formatter.Print(TestStruct{5})
65+
formatter.Print("a string")
6566

6667
formatter.SetFormatter("json")
6768
formatter.Print(TestStruct{10})
69+
formatter.Print("a string")
6870

6971
// Output:
7072
// VALUE = 5
73+
// a string
7174
// {"value":10}
7275
}

common/formatter/text.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ func (tp *TextFormatter) Format(msg interface{}) (string, error) {
3434
if msg == nil {
3535
return "<nil>", nil
3636
}
37+
if str, ok := msg.(string); ok {
38+
return str, nil
39+
}
3740
str, ok := msg.(fmt.Stringer)
3841
if !ok {
3942
return "", errors.New("object can't be formatted as text")

0 commit comments

Comments
 (0)