Skip to content

Commit

Permalink
fix a panic opportunity in xerrors.WithStack
Browse files Browse the repository at this point in the history
  • Loading branch information
bradenaw committed Jan 28, 2024
1 parent 0cc9a42 commit 5b729a3
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion xerrors/xerrors.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,17 @@ func (err withStack) Unwrap() error {
return err.inner
}

var noError = errors.New("no error")

// WithStack returns an error that wraps err and adds the call stack of the call to WithStack to
// Error(). If err is nil or already has a stack attached, returns err.
func WithStack(err error) error {
if err == nil {
return nil
}
if errors.Is(err, withStack{}) {
// use noError in case anything along err's chain has a custom Is that calls Error() for some
// reason.
if errors.Is(err, withStack{inner: noError}) {
return err
}
var buf [64]uintptr
Expand Down

0 comments on commit 5b729a3

Please sign in to comment.