typecheck: improve error stack parsing. (#1886)
This commit is contained in:
parent
3fee285ba6
commit
a833cc1600
3
.github/workflows/pr.yml
vendored
3
.github/workflows/pr.yml
vendored
@ -33,6 +33,9 @@ jobs:
|
|||||||
uses: golangci/golangci-lint-action@v2.5.1
|
uses: golangci/golangci-lint-action@v2.5.1
|
||||||
with:
|
with:
|
||||||
version: latest
|
version: latest
|
||||||
|
# skip cache because of flaky behaviors
|
||||||
|
skip-build-cache: true
|
||||||
|
|
||||||
tests-on-windows:
|
tests-on-windows:
|
||||||
needs: golangci-lint # run after golangci-lint action to not produce duplicated errors
|
needs: golangci-lint # run after golangci-lint action to not produce duplicated errors
|
||||||
runs-on: windows-latest
|
runs-on: windows-latest
|
||||||
|
@ -2,11 +2,16 @@ package packages
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"golang.org/x/tools/go/packages"
|
"golang.org/x/tools/go/packages"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// reFile matches a line who starts with path and position.
|
||||||
|
// ex: `/example/main.go:11:17: foobar`
|
||||||
|
var reFile = regexp.MustCompile(`^.+\.go:\d+:\d+: .+`)
|
||||||
|
|
||||||
func ExtractErrors(pkg *packages.Package) []packages.Error {
|
func ExtractErrors(pkg *packages.Package) []packages.Error {
|
||||||
errors := extractErrorsImpl(pkg, map[*packages.Package]bool{})
|
errors := extractErrorsImpl(pkg, map[*packages.Package]bool{})
|
||||||
if len(errors) == 0 {
|
if len(errors) == 0 {
|
||||||
@ -89,5 +94,9 @@ func stackCrusher(msg string) string {
|
|||||||
|
|
||||||
frag := msg[index+1 : lastIndex]
|
frag := msg[index+1 : lastIndex]
|
||||||
|
|
||||||
|
if !reFile.MatchString(frag) {
|
||||||
|
return msg
|
||||||
|
}
|
||||||
|
|
||||||
return stackCrusher(frag)
|
return stackCrusher(frag)
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,16 @@ func Test_stackCrusher(t *testing.T) {
|
|||||||
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`,
|
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`,
|
||||||
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",
|
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",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
desc: "stack with message with parenthesis at the end",
|
||||||
|
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))`,
|
||||||
|
expected: "/home/username/childapp/vendor/github.com/gotk3/gotk3/gtk/aboutdialog.go:5:8: could not import C (cgo preprocessing failed)",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "no stack but message with parenthesis at the end",
|
||||||
|
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)`,
|
||||||
|
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)",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range testCases {
|
for _, test := range testCases {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user