Skip to content

Commit 217efed

Browse files
committed
Set get frames public
1 parent 9f7c73f commit 217efed

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

error.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,9 @@ func (e *Error) Unwrap() error {
170170
// Format implements the Formatter interface.
171171
// Supported verbs:
172172
//
173-
// %s simple message output
174-
// %v same as %s
175-
// %+v full output complete with a stack trace
173+
// %s simple message output
174+
// %v same as %s
175+
// %+v full output complete with a stack trace
176176
//
177177
// In is nearly always preferable to use %+v format.
178178
// If a stack trace is not required, it should be omitted at the moment of creation rather in formatting.
@@ -189,6 +189,20 @@ func (e *Error) Format(s fmt.State, verb rune) {
189189
}
190190
}
191191

192+
// GetFrames exports stacktrace as frame slice.
193+
func (e *Error) GetFrames() []Frame {
194+
if e.stackTrace == nil {
195+
return nil
196+
}
197+
198+
pc, _ := e.stackTrace.deduplicateFramesWithCause()
199+
if len(pc) == 0 {
200+
return nil
201+
}
202+
203+
return frameHelperSingleton.GetFrames(pc)
204+
}
205+
192206
// Error implements the error interface.
193207
// A result is the same as with %s formatter and does not contain a stack trace.
194208
func (e *Error) Error() string {

stackframe.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"runtime"
55
)
66

7-
type frame interface {
7+
type Frame interface {
88
Function() string
99
File() string
1010
Line() int
@@ -31,9 +31,9 @@ func (f *defaultFrame) Line() int {
3131
return f.frame.Line
3232
}
3333

34-
func (c *frameHelper) GetFrames(pcs []uintptr) []frame {
34+
func (c *frameHelper) GetFrames(pcs []uintptr) []Frame {
3535
frames := runtime.CallersFrames(pcs[:])
36-
result := make([]frame, 0, len(pcs))
36+
result := make([]Frame, 0, len(pcs))
3737

3838
var rawFrame runtime.Frame
3939
next := true

stacktrace.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ var transformStackTraceLineNoop StackTraceFilePathTransformer = func(line string
5555

5656
const (
5757
stackTraceDepth = 128
58-
// tuned so that in all control paths of error creation the first frame is useful
58+
// tuned so that in all control paths of error creation the first Frame is useful
5959
// that is, the frame where New/Wrap/Decorate etc. are called; see TestStackTraceStart
6060
skippedFrames = 6
6161
)

0 commit comments

Comments
 (0)