| 105 | } |
| 106 | |
| 107 | func (p *stackParser) Parse() ([]Stack, error) { |
| 108 | for p.scan.Scan() { |
| 109 | line := p.scan.Text() |
| 110 | |
| 111 | // If we see the goroutine header, start a new stack. |
| 112 | if strings.HasPrefix(line, "goroutine ") { |
| 113 | stack, err := p.parseStack(line) |
| 114 | if err != nil { |
| 115 | p.errors = append(p.errors, err) |
| 116 | continue |
| 117 | } |
| 118 | p.stacks = append(p.stacks, stack) |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | p.errors = append(p.errors, p.scan.Err()) |
| 123 | return p.stacks, errors.Join(p.errors...) |
| 124 | } |
| 125 | |
| 126 | // parseStack parses a single stack trace from the given scanner. |
| 127 | // line is the first line of the stack trace, which should look like: |