Skip to content

Commit 1b876e0

Browse files
committed
Remove WithStack and WithMessage public functions
The refactoring to use withStack and withMessage types is useful enough to land indepdently of exposing these helpers publically.
1 parent 777ed74 commit 1b876e0

File tree

2 files changed

+2
-26
lines changed

2 files changed

+2
-26
lines changed

errors.go

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

135-
// WithStack annotates err with a stack trace at the point WithStack was called.
136-
// If err is nil, WithStack returns nil.
137-
func WithStack(err error) error {
138-
if err == nil {
139-
return nil
140-
}
141-
return &withStack{
142-
err,
143-
callers(),
144-
}
145-
}
146-
147135
type withStack struct {
148136
error
149137
*stack
@@ -205,18 +193,6 @@ func Wrapf(err error, format string, args ...interface{}) error {
205193
}
206194
}
207195

208-
// WithMessage annotates err with a new message.
209-
// If err is nil, WithStack returns nil.
210-
func WithMessage(err error, message string) error {
211-
if err == nil {
212-
return nil
213-
}
214-
return &withMessage{
215-
cause: err,
216-
msg: message,
217-
}
218-
}
219-
220196
type withMessage struct {
221197
cause error
222198
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 _, tt := range tests {
158+
for i, 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, got, "%s", tt.want)
163+
testFormatRegexp(t, i, got, "%s", tt.want)
164164
}
165165
}
166166

0 commit comments

Comments
 (0)