Skip to content

Commit 4de4fc5

Browse files
committed
stackFormatter: Replace counter with a bool
Track whether we've written at least one frame, and use that to decide if we need the prefix.
1 parent 83f6340 commit 4de4fc5

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

stacktrace.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ func takeStacktrace(skip int) string {
141141

142142
// stackFormatter formats a stack trace into a readable string representation.
143143
type stackFormatter struct {
144-
i int // number of frames already written
145-
b *buffer.Buffer
144+
b *buffer.Buffer
145+
nonEmpty bool // whehther we've written at least one frame already
146146
}
147147

148148
// newStackFormatter builds a new stackFormatter.
@@ -163,10 +163,10 @@ func (sf *stackFormatter) FormatStack(stack *stacktrace) {
163163

164164
// FormatFrame formats the given frame.
165165
func (sf *stackFormatter) FormatFrame(frame runtime.Frame) {
166-
if sf.i != 0 {
166+
if sf.nonEmpty {
167167
sf.b.AppendByte('\n')
168168
}
169-
sf.i++
169+
sf.nonEmpty = true
170170
sf.b.AppendString(frame.Function)
171171
sf.b.AppendByte('\n')
172172
sf.b.AppendByte('\t')

0 commit comments

Comments
 (0)