123456789101112131415161718192021222324252627282930313233343536 |
- package fserr
- import (
- "fmt"
- "github.com/pkg/errors"
- "runtime"
- )
- // stack represents a stack of program counters.
- type stack []uintptr
- func (s *stack) Format(st fmt.State, verb rune) {
- switch verb {
- case 'v':
- switch {
- case st.Flag('+'):
- for _, pc := range *s {
- fmt.Fprintf(st, "\n%+v", errors.Frame(pc))
- }
- }
- }
- }
- func (s *stack) StackTrace() errors.StackTrace {
- f := make([]errors.Frame, len(*s))
- for i := 0; i < len(f); i++ {
- f[i] = errors.Frame((*s)[i])
- }
- return f
- }
- func callers() *stack {
- var pcs [32]uintptr
- var st stack = pcs[0:runtime.Callers(3, pcs[:])]
- return &st
- }
|