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

Commit 4f8d1cf

Browse files
committed
Revert "Remove WithStack and WithMessage public functions"
This reverts commit 1b876e0.
1 parent a887431 commit 4f8d1cf

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

errors.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,18 @@ func (f *fundamental) Format(s fmt.State, verb rune) {
134134
}
135135
}
136136

137+
// WithStack annotates err with a stack trace at the point WithStack was called.
138+
// If err is nil, WithStack returns nil.
139+
func WithStack(err error) error {
140+
if err == nil {
141+
return nil
142+
}
143+
return &withStack{
144+
err,
145+
callers(),
146+
}
147+
}
148+
137149
type withStack struct {
138150
error
139151
*stack
@@ -189,6 +201,18 @@ func Wrapf(err error, format string, args ...interface{}) error {
189201
}
190202
}
191203

204+
// WithMessage annotates err with a new message.
205+
// If err is nil, WithStack returns nil.
206+
func WithMessage(err error, message string) error {
207+
if err == nil {
208+
return nil
209+
}
210+
return &withMessage{
211+
cause: err,
212+
msg: message,
213+
}
214+
}
215+
192216
type withMessage struct {
193217
cause error
194218
msg string

stack_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,12 @@ func TestTrimGOPATH(t *testing.T) {
155155
"github.com/pkg/errors/stack_test.go",
156156
}}
157157

158-
for i, tt := range tests {
158+
for _, tt := range tests {
159159
pc := tt.Frame.pc()
160160
fn := runtime.FuncForPC(pc)
161161
file, _ := fn.FileLine(pc)
162162
got := trimGOPATH(fn.Name(), file)
163-
testFormatRegexp(t, i, got, "%s", tt.want)
163+
testFormatRegexp(t, got, "%s", tt.want)
164164
}
165165
}
166166

0 commit comments

Comments
 (0)