Skip to content

Commit d14e9e6

Browse files
committed
cmd/go: stop early in disallowInternal on erroneous packages
Fixes #11201 Change-Id: I80d8fcfcb5c856aaf9d0e73d756d86018e2bec3b Reviewed-on: https://go-review.googlesource.com/11110 Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 7d48237 commit d14e9e6

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

src/cmd/go/go_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,12 @@ func testMove(t *testing.T, vcs, url, base, config string) {
875875
tg.grepStderr("validating server certificate|not found", "go get -d -f -u "+url+" failed for wrong reason")
876876
}
877877

878+
func TestInternalPackageErrorsAreHandled(t *testing.T) {
879+
tg := testgo(t)
880+
defer tg.cleanup()
881+
tg.run("list", "./testdata/testinternal3")
882+
}
883+
878884
func TestMoveGit(t *testing.T) {
879885
testMove(t, "git", "rsc.io/pdf", "pdf", "rsc.io/pdf/.git/config")
880886
}

src/cmd/go/pkg.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,11 @@ func disallowInternal(srcDir string, p *Package, stk *importStack) *Package {
327327
// is disallowed if the importing code is outside the tree
328328
// rooted at the parent of the “internal” directory.
329329

330+
// There was an error loading the package; stop here.
331+
if p.Error != nil {
332+
return p
333+
}
334+
330335
// The stack includes p.ImportPath.
331336
// If that's the only thing on the stack, we started
332337
// with a name given on the command line, not an
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package t
2+
3+
import _ "internal/does-not-exist"

0 commit comments

Comments
 (0)