File tree Expand file tree Collapse file tree 3 files changed +21
-7
lines changed Expand file tree Collapse file tree 3 files changed +21
-7
lines changed Original file line number Diff line number Diff 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.
194208func (e * Error ) Error () string {
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change @@ -55,7 +55,7 @@ var transformStackTraceLineNoop StackTraceFilePathTransformer = func(line string
5555
5656const (
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)
You can’t perform that action at this time.
0 commit comments