Skip to content

Commit e41050e

Browse files
gregwebslysu
authored andcommitted
move GetStackTracer to stack.go (#7)
1 parent 0548e8c commit e41050e

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

errors.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -173,22 +173,6 @@ func AddStack(err error) error {
173173
return WithStack(err)
174174
}
175175

176-
// GetStackTracer will return the first StackTracer in the causer chain.
177-
// This function is used by AddStack to avoid creating redundant stack traces.
178-
//
179-
// You can also use the StackTracer interface on the returned error to get the stack trace.
180-
func GetStackTracer(origErr error) StackTracer {
181-
var stacked StackTracer
182-
WalkDeep(origErr, func(err error) bool {
183-
if stackTracer, ok := err.(StackTracer); ok {
184-
stacked = stackTracer
185-
return true
186-
}
187-
return false
188-
})
189-
return stacked
190-
}
191-
192176
type withStack struct {
193177
error
194178
*stack

stack.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,22 @@ type StackTracer interface {
1414
StackTrace() StackTrace
1515
}
1616

17+
// GetStackTracer will return the first StackTracer in the causer chain.
18+
// This function is used by AddStack to avoid creating redundant stack traces.
19+
//
20+
// You can also use the StackTracer interface on the returned error to get the stack trace.
21+
func GetStackTracer(origErr error) StackTracer {
22+
var stacked StackTracer
23+
WalkDeep(origErr, func(err error) bool {
24+
if stackTracer, ok := err.(StackTracer); ok {
25+
stacked = stackTracer
26+
return true
27+
}
28+
return false
29+
})
30+
return stacked
31+
}
32+
1733
// Frame represents a program counter inside a stack frame.
1834
type Frame uintptr
1935

0 commit comments

Comments
 (0)