Skip to content

Commit

Permalink
Revert "Remove WithStack and WithMessage public functions"
Browse files Browse the repository at this point in the history
This reverts commit 1b876e0.
  • Loading branch information
davecheney committed Sep 29, 2016
1 parent a887431 commit 4f8d1cf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
24 changes: 24 additions & 0 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,18 @@ 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 {
error
*stack
Expand Down Expand Up @@ -189,6 +201,18 @@ 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 {
cause error
msg string
Expand Down
4 changes: 2 additions & 2 deletions stack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,12 @@ func TestTrimGOPATH(t *testing.T) {
"github.com/pkg/errors/stack_test.go",
}}

for i, tt := range tests {
for _, tt := range tests {
pc := tt.Frame.pc()
fn := runtime.FuncForPC(pc)
file, _ := fn.FileLine(pc)
got := trimGOPATH(fn.Name(), file)
testFormatRegexp(t, i, got, "%s", tt.want)
testFormatRegexp(t, got, "%s", tt.want)
}
}

Expand Down

0 comments on commit 4f8d1cf

Please sign in to comment.