Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
62 lines (52 sloc) 1.54 KB
// Copyright 2015 Dave Cheney <>. All rights reserved.
// Use of this source code (or at least parts of it) is governed by a BSD-style
// license that can be found in the LICENSE_THIRD_PARTY file.
package errors
import (
// StackTrace is stack of Frames from innermost (newest) to outermost (oldest).
// It is an alias of the same type in
type StackTrace = errors.StackTrace
// Frame represents a program counter inside a stack frame.
// For historical reasons if Frame is interpreted as a uintptr
// its value represents the program counter + 1.
// It is an alias of the same type in
type Frame = errors.Frame
// stack represents a stack of program counters.
// It is a duplicate of the same (sadly unexported) type in
type stack []uintptr
// nolint: gocritic
func (s *stack) Format(st fmt.State, verb rune) {
switch verb {
case 'v':
switch {
case st.Flag('+'):
for _, pc := range *s {
f := Frame(pc)
fmt.Fprintf(st, "\n%+v", f)
func (s *stack) StackTrace() StackTrace {
f := make([]Frame, len(*s))
for i := 0; i < len(f); i++ {
f[i] = Frame((*s)[i])
return f
// callers is based on the function with the same name in,
// but accepts a custom depth (useful to customize the error constructor caller depth).
func callers(depth int) *stack {
const maxDepth = 32
var pcs [maxDepth]uintptr
n := runtime.Callers(2+depth, pcs[:])
var st stack = pcs[0:n]
return &st
You can’t perform that action at this time.