aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/load/pkg.go
diff options
context:
space:
mode:
authorBryan C. Mills <bcmills@google.com>2021-03-23 11:57:36 -0400
committerBryan C. Mills <bcmills@google.com>2021-03-25 03:19:56 +0000
commit4889afe8f82433599a38b74808eb572f972d4ff9 (patch)
tree70191395126d5dfbdf6fdad8933070ad22ef0afa /src/cmd/go/internal/load/pkg.go
parentadb037d67ad46491bb0e9c2a09b56e89dd8a3617 (diff)
downloadgo-4889afe8f82433599a38b74808eb572f972d4ff9.tar.gz
go-4889afe8f82433599a38b74808eb572f972d4ff9.zip
cmd/go/internal/load: use setLoadPackageDataError in loadImport
This makes the error handling in loadImport somewhat more uniform, with no discernable effect on reported errors. Noticed in CL 303869. Updates #36087 Updates #38034 This somewhat simplifies the code, with no discernable effect on Change-Id: I30521f658f264d6f99d1844d6701269bbb372246 Reviewed-on: https://go-review.googlesource.com/c/go/+/304069 Trust: Bryan C. Mills <bcmills@google.com> Run-TryBot: Bryan C. Mills <bcmills@google.com> Reviewed-by: Michael Matloob <matloob@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
Diffstat (limited to 'src/cmd/go/internal/load/pkg.go')
-rw-r--r--src/cmd/go/internal/load/pkg.go27
1 files changed, 15 insertions, 12 deletions
diff --git a/src/cmd/go/internal/load/pkg.go b/src/cmd/go/internal/load/pkg.go
index 66b6d0dc46..a6d730d0d8 100644
--- a/src/cmd/go/internal/load/pkg.go
+++ b/src/cmd/go/internal/load/pkg.go
@@ -672,22 +672,25 @@ func loadImport(ctx context.Context, pre *preload, path, srcDir string, parent *
pre.preloadImports(ctx, bp.Imports, bp)
}
if bp == nil {
- if importErr, ok := err.(ImportPathError); !ok || importErr.ImportPath() != path {
- // Only add path to the error's import stack if it's not already present on the error.
- stk.Push(path)
- defer stk.Pop()
- }
- // TODO(bcmills): Why are we constructing Error inline here instead of
- // calling setLoadPackageDataError?
- return &Package{
+ p := &Package{
PackagePublic: PackagePublic{
ImportPath: path,
- Error: &PackageError{
- ImportStack: stk.Copy(),
- Err: err,
- },
+ Incomplete: true,
},
}
+ if importErr, ok := err.(ImportPathError); !ok || importErr.ImportPath() != path {
+ // Only add path to the error's import stack if it's not already present
+ // in the error.
+ //
+ // TODO(bcmills): setLoadPackageDataError itself has a similar Push / Pop
+ // sequence that empirically doesn't trigger for these errors, guarded by
+ // a somewhat complex condition. Figure out how to generalize that
+ // condition and eliminate the explicit calls here.
+ stk.Push(path)
+ defer stk.Pop()
+ }
+ p.setLoadPackageDataError(err, path, stk, nil)
+ return p
}
importPath := bp.ImportPath