// NewStackError produces a StackError object, collecting the
// stacktrace and building a Formatted message composer
// (e.g. fmt.Sprintf).
358031
func NewStackError(messageFmt string, args ...interface{}) *StackError {
	return &StackError{
		Composer:   message.NewFormatted(messageFmt, args...),
		Stacktrace: stacktrace(),
	}
}
784776
func (stack *ErrorStack) PushAndDescribe(message string, err error) bool {
	if err != nil {
		stack.errors = append(stack.errors, fmt.Errorf(message+" %s", err.Error()))
		return true
	}
	return false
}
624882
func (c *Client) RequestErrorWithStackSkip(level string, r *http.Request, err error, skip int) {
	c.RequestErrorWithStackSkipWithExtras(level, r, err, skip, noExtras)
}
1264543
func New(text string) error {
	if AddStack {
		text += "\n" + string(debug.Stack())
	}
	return &errorString{text}
}
373949
func NewError(packageType string, method string, message string, args ...interface{}) Error {
	return Error{
		PackageType: packageType,
		Method:      method,
		Message:     fmt.Sprintf(message, args...),
	}
}
576588
func (L *State) StackTrace() []LuaStackEntry {
	r := []LuaStackEntry{}
	var d C.lua_Debug
	Sln := C.CString("Sln")
	defer C.free(unsafe.Pointer(Sln))

	for depth := 0; C.lua_getstack(L.s, C.int(depth), &d) > 0; depth++ {
		C.lua_getinfo(L.s, Sln, &d)
		ssb := make([]byte, C.LUA_IDSIZE)
		for i := 0; i < C.LUA_IDSIZE; i++ {
			ssb[i] = byte(d.short_src[i])
			if ssb[i] == 0 {
				ssb = ssb[:i]
				break
			}
		}
		ss := string(ssb)

		r = append(r, LuaStackEntry{C.GoString(d.name), C.GoString(d.source), ss, int(d.currentline)})
	}

	return r
}
940694
func (e *baseError) GetStack() string {
	stackFrames := e.StackFrames()
	buf := bytes.NewBuffer(make([]byte, 0, 256))
	for _, frame := range stackFrames {
		_, _ = buf.WriteString(frame.FuncName)
		_, _ = buf.WriteString("\n")
		fmt.Fprintf(buf, "\t%s:%d +0x%x\n",
			frame.File, frame.LineNumber, frame.PC)
	}
	return buf.String()
}
1243186
func WithStacksAndMessage(err error, format string, args ...interface{}) error {
	if err == nil {
		// Remain no-error.
		return nil
	}
	s := stacks(2)
	ews, ok := err.(*ErrorWithStacks)
	if !ok || len(ews.Stacks) < len(s) {
		s[0] += ": " + errorPrintf(format, args...)
		return &ErrorWithStacks{
			Err:    err,
			Stacks: s,
		}
	}
	ews.Stacks[len(ews.Stacks)-len(s)] += ": " + fmt.Sprintf(format, args...)
	return ews
}
297001
func ExposeStackTrace(err error) error {
	if err == nil {
		return err
	}

	st, ok := getStackTracer(err)
	if !ok {
		return err
	}

	return &withStack{
		err: err,
		st:  st,
	}
}
1007417
func (s *Stack) SetStackErrors(v []*StackError) *Stack {
	s.StackErrors = v
	return s
}
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)
}
185951
func ErrorWithStackSkipWithExtrasAndContext(ctx context.Context, level string, err error, skip int, extras map[string]interface{}) {
	std.ErrorWithStackSkipWithExtrasAndContext(ctx, level, err, skip, extras)
}
166415
func RegisterStackDumper() {
	go func() {
		sigs := make(chan os.Signal, 1)
		signal.Notify(sigs, syscall.SIGUSR1)
		for {
			<-sigs
			LogStack()
		}
	}()
}
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
}
413540
func NewStrictDecodingError(message string, data string) error {
	return &strictDecodingError{
		message: message,
		data:    data,
	}
}
1185644
func buildStack(frames []runtime.Frame) stack {
	stack := make(stack, len(frames))

	for i, fr := range frames {
		file := shortenFilePath(fr.File)
		stack[i] = frame{file, functionName(fr.Function), fr.Line}
	}

	return stack
}
1046941
func NewStackWithSpinnerAndGrowSize(size, grow int, spin Spinner) Stack {
	return Stack{
		data:   make([]interface{}, tmath.MinI(size, 1)),
		growBy: tmath.MinI(grow, 1),
		head:   new(uint32),
		spin:   spin,
	}
}