diff options
author | Jay Conrod <jayconrod@google.com> | 2019-10-08 13:16:33 -0400 |
---|---|---|
committer | Jay Conrod <jayconrod@google.com> | 2019-10-09 20:31:55 +0000 |
commit | 32b6eb80fc727b852965b17a63c83b4c5dab2973 (patch) | |
tree | 0729564f213df6c7ee643d71da5f9c66dd2cccb2 /src/cmd/go/internal/get/get.go | |
parent | b3104fe3af99c965b5e9a954264dfc384f21bb37 (diff) | |
download | go-32b6eb80fc727b852965b17a63c83b4c5dab2973.tar.gz go-32b6eb80fc727b852965b17a63c83b4c5dab2973.zip |
cmd/go: eliminate redundancy in import error messages
This change introduces a new interface, load.ImportPathError. An error
may satisfy this by providing an ImportPath method and including the
import path in its error text. modload.ImportMissingError satisfies
this interface. load.ImportErrorf also provides a convenient way to
create an error satisfying this interface with an arbitrary message.
When load.PackageError formats its error text, it may omit the last
path on the import stack if the wrapped error satisfies
ImportPathError and has a matching path.
To make this work, PackageError.Err is now an error instead of a
string. PackageError.MarshalJSON will write Err as a string for
'go list -json' output.
When go/build.Import invokes 'go list' in module mode, it now runs
with '-e' and includes '.Error' in the output format instead of
expecting the error to be in the raw stderr text. If a package error
is printed and a directory was not found, the error will be returned
without extra decoration.
Fixes #34752
Change-Id: I2d81dab7dec19e0ae9f51f6412bc9f30433a8596
Reviewed-on: https://go-review.googlesource.com/c/go/+/199840
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Diffstat (limited to 'src/cmd/go/internal/get/get.go')
-rw-r--r-- | src/cmd/go/internal/get/get.go | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/cmd/go/internal/get/get.go b/src/cmd/go/internal/get/get.go index 44fd316f35..421f1bab75 100644 --- a/src/cmd/go/internal/get/get.go +++ b/src/cmd/go/internal/get/get.go @@ -274,7 +274,7 @@ func download(arg string, parent *load.Package, stk *load.ImportStack, mode int) stk.Push(arg) err := downloadPackage(p) if err != nil { - base.Errorf("%s", &load.PackageError{ImportStack: stk.Copy(), Err: err.Error()}) + base.Errorf("%s", &load.PackageError{ImportStack: stk.Copy(), Err: err}) stk.Pop() return } @@ -355,7 +355,7 @@ func download(arg string, parent *load.Package, stk *load.ImportStack, mode int) stk.Push(path) err := &load.PackageError{ ImportStack: stk.Copy(), - Err: "must be imported as " + path[j+len("vendor/"):], + Err: load.ImportErrorf(path, "%s must be imported as %s", path, path[j+len("vendor/"):]), } stk.Pop() base.Errorf("%s", err) |