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 {
170
170
// Format implements the Formatter interface.
171
171
// Supported verbs:
172
172
//
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
176
176
//
177
177
// In is nearly always preferable to use %+v format.
178
178
// 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) {
189
189
}
190
190
}
191
191
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
+
192
206
// Error implements the error interface.
193
207
// A result is the same as with %s formatter and does not contain a stack trace.
194
208
func (e * Error ) Error () string {
Original file line number Diff line number Diff line change 4
4
"runtime"
5
5
)
6
6
7
- type frame interface {
7
+ type Frame interface {
8
8
Function () string
9
9
File () string
10
10
Line () int
@@ -31,9 +31,9 @@ func (f *defaultFrame) Line() int {
31
31
return f .frame .Line
32
32
}
33
33
34
- func (c * frameHelper ) GetFrames (pcs []uintptr ) []frame {
34
+ func (c * frameHelper ) GetFrames (pcs []uintptr ) []Frame {
35
35
frames := runtime .CallersFrames (pcs [:])
36
- result := make ([]frame , 0 , len (pcs ))
36
+ result := make ([]Frame , 0 , len (pcs ))
37
37
38
38
var rawFrame runtime.Frame
39
39
next := true
Original file line number Diff line number Diff line change @@ -55,7 +55,7 @@ var transformStackTraceLineNoop StackTraceFilePathTransformer = func(line string
55
55
56
56
const (
57
57
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
59
59
// that is, the frame where New/Wrap/Decorate etc. are called; see TestStackTraceStart
60
60
skippedFrames = 6
61
61
)
You can’t perform that action at this time.
0 commit comments