diff --git a/internal/stack/stacks.go b/internal/stack/stacks.go index 9134592..58d6219 100644 --- a/internal/stack/stacks.go +++ b/internal/stack/stacks.go @@ -137,10 +137,6 @@ func (p *stackParser) parseStack(line string) (Stack, error) { funcs := make(map[string]struct{}) for p.scan.Scan() { line := p.scan.Text() - if len(line) == 0 { - continue - } - if strings.HasPrefix(line, "goroutine ") { // If we see the goroutine header, // it's the end of this stack. @@ -152,6 +148,10 @@ func (p *stackParser) parseStack(line string) (Stack, error) { fullStack.WriteString(line) fullStack.WriteByte('\n') // scanner trims the newline + if len(line) == 0 { + continue + } + funcName, err := parseFuncName(line) if err != nil { return Stack{}, fmt.Errorf("parse function: %w", err) @@ -170,6 +170,8 @@ func (p *stackParser) parseStack(line string) (Stack, error) { if p.scan.Scan() { bs := p.scan.Bytes() if len(bs) > 0 && bs[0] == '\t' { + fullStack.Write(bs) + fullStack.WriteByte('\n') continue } diff --git a/internal/stack/stacks_test.go b/internal/stack/stacks_test.go index 3ccdc21..9558ec6 100644 --- a/internal/stack/stacks_test.go +++ b/internal/stack/stacks_test.go @@ -105,6 +105,9 @@ func TestCurrent(t *testing.T) { assert.True(t, got.HasFunction("testing.(*T).Run"), "missing in stack: %v\n%s", "testing.(*T).Run", all) + assert.Contains(t, all, "stack/stacks_test.go", + "file name missing in stack:\n%s", all) + // Ensure that we are not returning the buffer without slicing it // from getStackBuffer. if len(got.Full()) > 1024 {