Skip to content
This repository was archived by the owner on Dec 1, 2021. It is now read-only.

Commit 0bc61eb

Browse files
authored
Wrapper errors now print full stacktrace (#57)
1 parent 494e70f commit 0bc61eb

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

errors.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ func (w wrapper) Format(s fmt.State, verb rune) {
145145
case 'v':
146146
if s.Flag('+') {
147147
fmt.Fprintf(s, "%+v\n", w.Cause())
148-
fmt.Fprintf(s, "%+v: %s", w.StackTrace()[0], w.msg)
148+
io.WriteString(s, w.msg)
149+
fmt.Fprintf(s, "%+v", w.StackTrace())
149150
return
150151
}
151152
fallthrough

format_test.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,9 @@ func TestFormatWrapf(t *testing.T) {
107107
Wrap(io.EOF, "error"),
108108
"%+v",
109109
"EOF\n" +
110+
"error\n" +
110111
"github.com/pkg/errors.TestFormatWrapf\n" +
111-
"\t.+/github.com/pkg/errors/format_test.go:107: error",
112+
"\t.+/github.com/pkg/errors/format_test.go:107",
112113
}, {
113114
Wrapf(New("error"), "error%d", 2),
114115
"%v",
@@ -118,7 +119,14 @@ func TestFormatWrapf(t *testing.T) {
118119
"%+v",
119120
"error\n" +
120121
"github.com/pkg/errors.TestFormatWrapf\n" +
121-
"\t.+/github.com/pkg/errors/format_test.go:117",
122+
"\t.+/github.com/pkg/errors/format_test.go:118",
123+
}, {
124+
Wrap(Wrap(io.EOF, "error1"), "error2"),
125+
"%+v",
126+
"EOF\n" +
127+
"error1\n" +
128+
"github.com/pkg/errors.TestFormatWrapf\n" +
129+
"\t.+/github.com/pkg/errors/format_test.go:124\n",
122130
}}
123131

124132
for _, tt := range tests {

0 commit comments

Comments
 (0)