mirror of
https://github.com/pkg/errors.git
synced 2025-04-27 13:12:40 +00:00
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.
This commit is contained in:
parent
777ed74de5
commit
1b876e063e
24
errors.go
24
errors.go
@ -132,18 +132,6 @@ func (f *fundamental) Format(s fmt.State, verb rune) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithStack annotates err with a stack trace at the point WithStack was called.
|
|
||||||
// If err is nil, WithStack returns nil.
|
|
||||||
func WithStack(err error) error {
|
|
||||||
if err == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return &withStack{
|
|
||||||
err,
|
|
||||||
callers(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type withStack struct {
|
type withStack struct {
|
||||||
error
|
error
|
||||||
*stack
|
*stack
|
||||||
@ -205,18 +193,6 @@ func Wrapf(err error, format string, args ...interface{}) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithMessage annotates err with a new message.
|
|
||||||
// If err is nil, WithStack returns nil.
|
|
||||||
func WithMessage(err error, message string) error {
|
|
||||||
if err == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return &withMessage{
|
|
||||||
cause: err,
|
|
||||||
msg: message,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type withMessage struct {
|
type withMessage struct {
|
||||||
cause error
|
cause error
|
||||||
msg string
|
msg string
|
||||||
|
@ -155,12 +155,12 @@ func TestTrimGOPATH(t *testing.T) {
|
|||||||
"github.com/pkg/errors/stack_test.go",
|
"github.com/pkg/errors/stack_test.go",
|
||||||
}}
|
}}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for i, tt := range tests {
|
||||||
pc := tt.Frame.pc()
|
pc := tt.Frame.pc()
|
||||||
fn := runtime.FuncForPC(pc)
|
fn := runtime.FuncForPC(pc)
|
||||||
file, _ := fn.FileLine(pc)
|
file, _ := fn.FileLine(pc)
|
||||||
got := trimGOPATH(fn.Name(), file)
|
got := trimGOPATH(fn.Name(), file)
|
||||||
testFormatRegexp(t, got, "%s", tt.want)
|
testFormatRegexp(t, i, got, "%s", tt.want)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user