Skip to content

Commit 412d287

Browse files
committed
Provide a better stacktrace if a panic occurs during text formatting
1 parent bd9d715 commit 412d287

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

common/formatter/text.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package formatter
1919

2020
import (
21+
"errors"
2122
"fmt"
2223
"time"
2324

@@ -30,7 +31,14 @@ type TextFormatter struct{}
3031

3132
// Format implements Formatter interface
3233
func (tp *TextFormatter) Format(msg interface{}) (string, error) {
33-
return fmt.Sprintf("%s", msg), nil
34+
if msg == nil {
35+
return "<nil>", nil
36+
}
37+
str, ok := msg.(fmt.Stringer)
38+
if !ok {
39+
return "", errors.New("object can't be formatted as text")
40+
}
41+
return str.String(), nil
3442
}
3543

3644
// DownloadProgressBar implements Formatter interface

0 commit comments

Comments
 (0)