Skip to content

Commit

Permalink
move GetStackTracer to stack.go (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
gregwebs authored and lysu committed Sep 11, 2018
1 parent 0548e8c commit e41050e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
16 changes: 0 additions & 16 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,22 +173,6 @@ func AddStack(err error) error {
return WithStack(err)
}

// GetStackTracer will return the first StackTracer in the causer chain.
// This function is used by AddStack to avoid creating redundant stack traces.
//
// You can also use the StackTracer interface on the returned error to get the stack trace.
func GetStackTracer(origErr error) StackTracer {
var stacked StackTracer
WalkDeep(origErr, func(err error) bool {
if stackTracer, ok := err.(StackTracer); ok {
stacked = stackTracer
return true
}
return false
})
return stacked
}

type withStack struct {
error
*stack
Expand Down
16 changes: 16 additions & 0 deletions stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,22 @@ type StackTracer interface {
StackTrace() StackTrace
}

// GetStackTracer will return the first StackTracer in the causer chain.
// This function is used by AddStack to avoid creating redundant stack traces.
//
// You can also use the StackTracer interface on the returned error to get the stack trace.
func GetStackTracer(origErr error) StackTracer {
var stacked StackTracer
WalkDeep(origErr, func(err error) bool {
if stackTracer, ok := err.(StackTracer); ok {
stacked = stackTracer
return true
}
return false
})
return stacked
}

// Frame represents a program counter inside a stack frame.
type Frame uintptr

Expand Down

0 comments on commit e41050e

Please sign in to comment.