Skip to content

Commit a833cc1

Browse files
authored
typecheck: improve error stack parsing. (#1886)
1 parent 3fee285 commit a833cc1

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

.github/workflows/pr.yml

+3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ jobs:
3333
uses: golangci/[email protected]
3434
with:
3535
version: latest
36+
# skip cache because of flaky behaviors
37+
skip-build-cache: true
38+
3639
tests-on-windows:
3740
needs: golangci-lint # run after golangci-lint action to not produce duplicated errors
3841
runs-on: windows-latest

pkg/packages/util.go

+9
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@ package packages
22

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

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

11+
// reFile matches a line who starts with path and position.
12+
// ex: `/example/main.go:11:17: foobar`
13+
var reFile = regexp.MustCompile(`^.+\.go:\d+:\d+: .+`)
14+
1015
func ExtractErrors(pkg *packages.Package) []packages.Error {
1116
errors := extractErrorsImpl(pkg, map[*packages.Package]bool{})
1217
if len(errors) == 0 {
@@ -89,5 +94,9 @@ func stackCrusher(msg string) string {
8994

9095
frag := msg[index+1 : lastIndex]
9196

97+
if !reFile.MatchString(frag) {
98+
return msg
99+
}
100+
92101
return stackCrusher(frag)
93102
}

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)