func TestCallersMulti(t *testing.T) { m := stack.CallersMulti(0) const expected = "github.com/facebookgo/stack/stack_test.go:35 TestCallersMulti" first := m.Stacks()[0][0].String() if first != expected { t.Fatalf(`expected "%s" got "%s"`, expected, first) } }
func TestCallersMultiWithTwo(t *testing.T) { m := stack.CallersMulti(0) m.AddCallers(0) matches := []string{ "^github.com/facebookgo/stack/stack_test.go:44 +TestCallersMultiWithTwo$", "", "", `^\(Stack 2\)$`, "^github.com/facebookgo/stack/stack_test.go:46 +TestCallersMultiWithTwo$", } match(t, m.String(), matches) }
// WrapSkip the error and add the current Stack. The argument skip is the // number of stack frames to ascend, with 0 identifying the caller of Wrap. If // the error to be wrapped has a MultiStack, the current stack will be added to // it. If the error to be wrapped is nil, a nil error is returned. func WrapSkip(err error, skip int) error { // nil errors are returned back as nil. if err == nil { return nil } // we're adding another Stack to an already wrapped error. if se, ok := err.(hasMultiStack); ok { se.MultiStack().AddCallers(skip + 1) return err } // we're create a freshly wrapped error. return &Error{ multiStack: stack.CallersMulti(skip + 1), underlying: err, } }