diff --git a/.gitignore b/.gitignore index 0fff519..038f681 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ vendor/ /lint.log /cover.out /cover.html +.idea/ \ No newline at end of file diff --git a/internal/stack/stacks.go b/internal/stack/stacks.go index 5ed5c0c..c4137ce 100644 --- a/internal/stack/stacks.go +++ b/internal/stack/stacks.go @@ -172,8 +172,9 @@ func (p *stackParser) parseStack(line string) (Stack, error) { // Just skip it. continue } - if strings.HasPrefix(line, "...") && strings.HasSuffix(line, " frames elided...") { - // e.g. ...23 frames elided... + trimmedLine := strings.TrimSpace(line) + if strings.HasPrefix(trimmedLine, "...") && strings.HasSuffix(trimmedLine, " frames elided...") { + // e.g. "...23 frames elided..." or " ...23 frames elided..." // This indicates frames were elided from the stack trace, // attempting to parse them via parseFuncName will fail resulting in a panic // and a relatively useless output. Gracefully handle this. diff --git a/internal/stack/stacks_test.go b/internal/stack/stacks_test.go index f26aebf..89f1b43 100644 --- a/internal/stack/stacks_test.go +++ b/internal/stack/stacks_test.go @@ -336,6 +336,24 @@ func TestParseStack(t *testing.T) { "example.com/foo/bar.baz", }, }, + { + name: "elided frames with leading whitespaces", + give: joinLines( + "goroutine 1 [running]:", + "example.com/foo/bar.baz()", + " example.com/foo/bar.go:123", + " ...23 frames elided...", + "created by example.com/foo/bar.qux", + " example.com/foo/bar.go:456", + ), + id: 1, + state: "running", + createdBy: "example.com/foo/bar.qux", + firstFunc: "example.com/foo/bar.baz", + funcs: []string{ + "example.com/foo/bar.baz", + }, + }, } for _, tt := range tests {