// return a new error with a new stack capture
359461
func (e *merryErr) WithStackSkipping(skip int) Error {
	if e == nil {
		return nil
	}
	return &merryErr{
		err:   e,
		key:   stack,
		value: captureStack(skip + 1),
	}
}
143954
func (stack *ErrorStack) Pushf(message string, args ...interface{}) {
	stack.errors = append(stack.errors, fmt.Errorf(message, args...))
}
729260
func CaptureErrorAndWait(err error, tags map[string]string, interfaces ...Interface) string {
	return DefaultClient.CaptureErrorAndWait(err, tags, interfaces...)
}
431084
func (s *Layer) UseError(fn c.HandlerFunc) Middleware {
	s.mtx.Lock()
	s.stack = append(s.stack, plugin.NewErrorPlugin(fn))
	s.mtx.Unlock()
	return s
}
674366
func ErrorWithStackSkip(level string, err error, skip int) {
	std.ErrorWithStackSkip(level, err, skip)
}
154794
func ErrorWithStack(level string, err error, stack Stack, fields ...*Field) {
	buildAndPushError(level, err, stack, fields...)
}
822725
func ExitError(ctx context.Context, exitCode int, err error, format string, args ...interface{}) error {
	if err != nil {
		out.Debug(ctx, "Stacktrace: %+v", err)
	}
	return cli.NewExitError(fmt.Sprintf(format, args...), exitCode)
}
964961
func (err *Error) Stack() []byte {
	buf := bytes.Buffer{}

	for _, frame := range err.StackFrames() {
		buf.WriteString(frame.String())
	}

	return buf.Bytes()
}
227685
func CaptureStacktrace(th *starlark.Thread, skip int) (*CapturedStacktrace, error) {
	f := th.Caller()
	skipped := 0
	for skipped < skip && f != nil {
		f = f.Parent()
		skipped++
	}
	if f == nil {
		return nil, fmt.Errorf("stacktrace: the stack is not deep enough to skip %d levels, has only %d frames", skip, skipped)
	}
	buf := strings.Builder{}
	f.WriteBacktrace(&buf)
	return &CapturedStacktrace{buf.String()}, nil
}
678150
func Error(code int, err error) *APIError {
	if err == nil {
		err = fmt.Errorf("Error pointer was nil")
	}

	return New(code, err.Error())
}
808650
func NewErrorsSkip(skip int, errs ...error) ErrorObject {
	var errcomp ErrorObject
	var errtmp ErrorObject
	for i, size := 0, len(errs); i < size; i++ {
		errtmp = castErrorObject(nil, skip+1, errs[i])
		if errtmp == nil {
			continue
		}

		if errcomp == nil {
			errcomp = errtmp
			continue
		}

		if err := AddParent(errcomp, errtmp); err != nil {
			panic(err)
		}
	}
	return errcomp
}
909488
func Stacktrace(e error) string {
	s := Stack(e)
	if len(s) > 0 {
		buf := bytes.Buffer{}
		frames := runtime.CallersFrames(s)
		for {
			frame, more := frames.Next()
			buf.WriteString(frame.Function)
			buf.WriteString(fmt.Sprintf("\n\t%s:%d\n", frame.File, frame.Line))
			if !more {
				break
			}

		}
		return buf.String()
	}
	return ""
}
1134715
func Catch(cb func(p *Panic)) {
	if reason := recover(); reason != nil && cb != nil {
		stack := make([]byte, maxStackBufferSize)
		count := runtime.Stack(stack, true)
		cb(&Panic{
			Reason: reason,
			Stack:  string(stack[:count]),
		})
	}
}
539302
func ErrorWithStackSkip(level string, err error, skip int, fields ...*Field) {
	stack := BuildStack(2 + skip)
	ErrorWithStack(level, err, stack, fields...)
}
348013
func (l *loop) Error() (status int, err error) {
	l.mux.Lock()
	defer l.mux.Unlock()
	status = l.status
	err = l.err
	return
}
766654
func Errorf(f string, args ...interface{}) *Error {
	e := &Error{
		stack: []errorStack{},
		desc:  fmt.Sprintf(f, args...),
	}

	i := 1

	for {
		stack := errorStack{}
		pc, file, line, ok := runtime.Caller(i)
		if !ok {
			break
		}

		fun := runtime.FuncForPC(pc)
		if fun != nil {
			stack.fun = fun.Name()
		}

		stack.file = path.Base(file)
		stack.line = line
		e.stack = append(e.stack, stack)

		i++
	}

	return e
}
868807
func (c *CompileContext) CaptureErrors(yes bool) {
	state := 0
	if yes {
		state = 1
	}

	C._go_mrb_context_set_capture_errors(c.ctx, C.int(state))
}