Skip to content

Commit c2c33dc

Browse files
committed
fix: improve error stack parsing.
1 parent 3fee285 commit c2c33dc

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

pkg/packages/util.go

+7
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@ package packages
22

33
import (
44
"fmt"
5+
"regexp"
56
"strings"
67

78
"golang.org/x/tools/go/packages"
89
)
910

11+
var reFile = regexp.MustCompile(`^.+\.go:\d+:\d+: .+`)
12+
1013
func ExtractErrors(pkg *packages.Package) []packages.Error {
1114
errors := extractErrorsImpl(pkg, map[*packages.Package]bool{})
1215
if len(errors) == 0 {
@@ -89,5 +92,9 @@ func stackCrusher(msg string) string {
8992

9093
frag := msg[index+1 : lastIndex]
9194

95+
if !reFile.MatchString(frag) {
96+
return msg
97+
}
98+
9299
return stackCrusher(frag)
93100
}

pkg/packages/util_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ func Test_stackCrusher(t *testing.T) {
2828
stack: `/home/ldez/sources/go/src/github.com/golangci/golangci-lint/pkg/golinters/deadcode.go:20:32: cannot use mu (variable of type sync.Mutex) as goanalysis.Issue value in argument to append`,
2929
expected: "/home/ldez/sources/go/src/github.com/golangci/golangci-lint/pkg/golinters/deadcode.go:20:32: cannot use mu (variable of type sync.Mutex) as goanalysis.Issue value in argument to append",
3030
},
31+
{
32+
desc: "stack with message with parenthesis at the end",
33+
stack: `/home/username/childapp/interfaces/IPanel.go:4:2: could not import github.com/gotk3/gotk3/gtk (/home/username/childapp/vendor/github.com/gotk3/gotk3/gtk/aboutdialog.go:5:8: could not import C (cgo preprocessing failed))`,
34+
expected: "/home/username/childapp/vendor/github.com/gotk3/gotk3/gtk/aboutdialog.go:5:8: could not import C (cgo preprocessing failed)",
35+
},
36+
{
37+
desc: "no stack but message with parenthesis at the end",
38+
stack: `/home/ldez/sources/go/src/github.com/golangci/sandbox/main.go:11:17: ui.test undefined (type App has no field or method test)`,
39+
expected: "/home/ldez/sources/go/src/github.com/golangci/sandbox/main.go:11:17: ui.test undefined (type App has no field or method test)",
40+
},
3141
}
3242

3343
for _, test := range testCases {

0 commit comments

Comments
 (0)