Skip to content

Commit

Permalink
cmd/go/internal/vet: print line numbers appropriately on list errors
Browse files Browse the repository at this point in the history
Fixes golang#36173

For reasons that are unclear to me, this commit:
golang@f1d5ce0
introduces a TestPackagesFor function that strips line numbers from error
messages. This commit introduces a new version of that function for 'go vet'
that always keeps the line numbers.
  • Loading branch information
nicks committed Feb 17, 2020
1 parent 753d56d commit 81c8ef2
Show file tree
Hide file tree
Showing 8 changed files with 260 additions and 93 deletions.
14 changes: 6 additions & 8 deletions src/cmd/go/internal/get/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,10 @@ func download(arg string, parent *load.Package, stk *load.ImportStack, mode int)
// Download if the package is missing, or update if we're using -u.
if p.Dir == "" || *getU {
// The actual download.
stk.Push(arg)
stk.Push(arg, nil)
err := downloadPackage(p)
if err != nil {
base.Errorf("%s", &load.PackageError{ImportStack: stk.Copy(), Err: err})
base.Errorf("%s", load.NewPackageError(stk, err))
stk.Pop()
return
}
Expand Down Expand Up @@ -329,7 +329,7 @@ func download(arg string, parent *load.Package, stk *load.ImportStack, mode int)
if isWildcard {
// Report both the real package and the
// wildcard in any error message.
stk.Push(p.ImportPath)
stk.Push(p.ImportPath, nil)
}

// Process dependencies, now that we know what they are.
Expand All @@ -352,11 +352,9 @@ func download(arg string, parent *load.Package, stk *load.ImportStack, mode int)
orig = p.Internal.Build.Imports[i]
}
if j, ok := load.FindVendor(orig); ok {
stk.Push(path)
err := &load.PackageError{
ImportStack: stk.Copy(),
Err: load.ImportErrorf(path, "%s must be imported as %s", path, path[j+len("vendor/"):]),
}
stk.Push(path, nil)
err := load.NewPackageError(stk,
load.ImportErrorf(path, "%s must be imported as %s", path, path[j+len("vendor/"):]))
stk.Pop()
base.Errorf("%s", err)
continue
Expand Down
Loading

0 comments on commit 81c8ef2

Please sign in to comment.