Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typecheck: improve error stack parsing. #1886

Merged
merged 2 commits into from Apr 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/pr.yml
Expand Up @@ -33,6 +33,9 @@ jobs:
uses: golangci/golangci-lint-action@v2.5.1
with:
version: latest
# skip cache because of flaky behaviors
skip-build-cache: true

tests-on-windows:
needs: golangci-lint # run after golangci-lint action to not produce duplicated errors
runs-on: windows-latest
Expand Down
9 changes: 9 additions & 0 deletions pkg/packages/util.go
Expand Up @@ -2,11 +2,16 @@ package packages

import (
"fmt"
"regexp"
"strings"

"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 {
errors := extractErrorsImpl(pkg, map[*packages.Package]bool{})
if len(errors) == 0 {
Expand Down Expand Up @@ -89,5 +94,9 @@ func stackCrusher(msg string) string {

frag := msg[index+1 : lastIndex]

if !reFile.MatchString(frag) {
return msg
}

return stackCrusher(frag)
}
10 changes: 10 additions & 0 deletions pkg/packages/util_test.go
Expand Up @@ -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`,
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 {
Expand Down