@@ -14,6 +14,15 @@ var DefaultLinesAfter = 2
14
14
// DefaultLinesBefore is number of source lines before traced line to display.
15
15
var DefaultLinesBefore = 3
16
16
17
+ // DefaultIgnoreFirstFrames is the number of first frames to ignore
18
+ var DefaultIgnoreFirstFrames = 0
19
+
20
+ // DefaultMaxFrames is the total number of frames to print/return (0 means "no limit")
21
+ var DefaultMaxFrames = 0
22
+
23
+ // DefaultIgnoreFirstFrames is the number of last frames to ignore
24
+ var DefaultIgnoreLastFrames = 0
25
+
17
26
var cache = map [string ][]string {}
18
27
19
28
var mutex sync.RWMutex
@@ -168,7 +177,13 @@ func sprint(err error, nums []int, colorized bool) string {
168
177
if withSource {
169
178
rows = append (rows , "" )
170
179
}
180
+ i := 0
181
+ appendedFrames := 0
171
182
for _ , frame := range frames {
183
+ i ++
184
+ if i <= DefaultIgnoreFirstFrames {
185
+ continue
186
+ }
172
187
message := frame .String ()
173
188
if colorized {
174
189
message = bold (message )
@@ -177,6 +192,13 @@ func sprint(err error, nums []int, colorized bool) string {
177
192
if withSource {
178
193
rows = sourceRows (rows , frame , before , after , colorized )
179
194
}
195
+ appendedFrames ++
196
+ if DefaultMaxFrames > 0 && appendedFrames >= DefaultMaxFrames {
197
+ break
198
+ }
199
+ if DefaultIgnoreLastFrames > 0 && i + DefaultIgnoreLastFrames >= len (frames ) {
200
+ break
201
+ }
180
202
}
181
203
return strings .Join (rows , "\n " )
182
204
}
0 commit comments