From 4889afe8f82433599a38b74808eb572f972d4ff9 Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Tue, 23 Mar 2021 11:57:36 -0400 Subject: [PATCH] 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 Run-TryBot: Bryan C. Mills Reviewed-by: Michael Matloob Reviewed-by: Jay Conrod --- src/cmd/go/internal/load/pkg.go | 27 +++++++++++++++------------ 1 file 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 -- 2.50.0