1
0
mirror of https://github.com/golang/go synced 2024-11-11 22:20:22 -07:00

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>
This commit is contained in:
Bryan C. Mills 2021-03-23 11:57:36 -04:00
parent adb037d67a
commit 4889afe8f8

View 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 {
p := &Package{
PackagePublic: PackagePublic{
ImportPath: path,
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 on the error.
// 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()
}
// TODO(bcmills): Why are we constructing Error inline here instead of
// calling setLoadPackageDataError?
return &Package{
PackagePublic: PackagePublic{
ImportPath: path,
Error: &PackageError{
ImportStack: stk.Copy(),
Err: err,
},
},
}
p.setLoadPackageDataError(err, path, stk, nil)
return p
}
importPath := bp.ImportPath