Skip to content

Commit a136106

Browse files
committed
add a way to ignore frames
implemented in the way discussed in upstream issue: ztrue#11
1 parent d626ed7 commit a136106

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

print.go

+22
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ var DefaultLinesAfter = 2
1414
// DefaultLinesBefore is number of source lines before traced line to display.
1515
var DefaultLinesBefore = 3
1616

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+
1726
var cache = map[string][]string{}
1827

1928
var mutex sync.RWMutex
@@ -168,7 +177,13 @@ func sprint(err error, nums []int, colorized bool) string {
168177
if withSource {
169178
rows = append(rows, "")
170179
}
180+
i := 0
181+
appendedFrames := 0
171182
for _, frame := range frames {
183+
i++
184+
if i <= DefaultIgnoreFirstFrames {
185+
continue
186+
}
172187
message := frame.String()
173188
if colorized {
174189
message = bold(message)
@@ -177,6 +192,13 @@ func sprint(err error, nums []int, colorized bool) string {
177192
if withSource {
178193
rows = sourceRows(rows, frame, before, after, colorized)
179194
}
195+
appendedFrames++
196+
if DefaultMaxFrames > 0 && appendedFrames >= DefaultMaxFrames {
197+
break
198+
}
199+
if DefaultIgnoreLastFrames > 0 && i + DefaultIgnoreLastFrames >= len(frames) {
200+
break
201+
}
180202
}
181203
return strings.Join(rows, "\n")
182204
}

0 commit comments

Comments
 (0)