]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go/internal/load: use setLoadPackageDataError in loadImport
authorBryan C. Mills <bcmills@google.com>
Tue, 23 Mar 2021 15:57:36 +0000 (11:57 -0400)
committerBryan C. Mills <bcmills@google.com>
Thu, 25 Mar 2021 03:19:56 +0000 (03:19 +0000)
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>
src/cmd/go/internal/load/pkg.go

index 66b6d0dc4677e9f1ad622eba1264f31835fab28f..a6d730d0d82e9e5e6ded1219955222d6668bf989 100644 (file)
@@ -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