Skip to content

Commit 9b7f4e0

Browse files
atomsymbol-notificationswheatman
authored andcommitted
cmd/go: do not miss an error if import path contains "cmd/something"
Fixes golang#7638 LGTM=rsc R=rsc, adg, robert.hencke, bradfitz CC=golang-codereviews https://golang.org/cl/89280043
1 parent 024ffb7 commit 9b7f4e0

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/cmd/go/get.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ var downloadRootCache = map[string]bool{}
140140
// for the package named by the argument.
141141
func download(arg string, stk *importStack, getTestDeps bool) {
142142
p := loadPackage(arg, stk)
143+
if p.Error != nil && p.Error.hard {
144+
errorf("%s", p.Error)
145+
return
146+
}
143147

144148
// There's nothing to do if this is a package in the standard library.
145149
if p.Standard {

src/cmd/go/pkg.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ type PackageError struct {
139139
Pos string // position of error
140140
Err string // the error itself
141141
isImportCycle bool // the error is an import cycle
142+
hard bool // whether the error is soft or hard; soft errors are ignored in some places
142143
}
143144

144145
func (p *PackageError) Error() string {
@@ -716,6 +717,7 @@ func loadPackage(arg string, stk *importStack) *Package {
716717
Error: &PackageError{
717718
ImportStack: stk.copy(),
718719
Err: fmt.Sprintf("invalid import path: cmd/... is reserved for Go commands"),
720+
hard: true,
719721
},
720722
}
721723
return p

0 commit comments

Comments
 (0)