Skip to content

Commit

Permalink
stackFormatter: Replace counter with a bool
Browse files Browse the repository at this point in the history
Track whether we've written at least one frame,
and use that to decide if we need the prefix.
  • Loading branch information
abhinav committed Jan 27, 2022
1 parent 83f6340 commit 4de4fc5
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions stacktrace.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ func takeStacktrace(skip int) string {

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

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

// FormatFrame formats the given frame.
func (sf *stackFormatter) FormatFrame(frame runtime.Frame) {
if sf.i != 0 {
if sf.nonEmpty {
sf.b.AppendByte('\n')
}
sf.i++
sf.nonEmpty = true
sf.b.AppendString(frame.Function)
sf.b.AppendByte('\n')
sf.b.AppendByte('\t')
Expand Down

0 comments on commit 4de4fc5

Please sign in to comment.