Skip to content

Commit 850c964

Browse files
committed
cmd/go: treat VCS errors as hard errors in module search
If we're looking for a module for a/b/c/d/e, we check for a module named a/b/c/d/e, then a/b/c/d, then a/b/c, then a/b, then a. If we know the source repo for a/b/c and that fails, we should report that error instead of continuing the loop: a/b and a are useless, and the error from a/b/c contains important information. The errors are now a bit more verbose than I'd like but they will suffice for Go 1.11. $ go get github.com/bradfitz/private/sonos go get github.com/bradfitz/private/sonos: git ls-remote -q origin in /Users/rsc/pkg/mod/cache/vcs/61e3c76780847e514802ec6af8f940f641c6017f711444f05c59cb17ac46d456: exit status 128: remote: Repository not found. fatal: repository 'https://github.com/bradfitz/private/' not found $ go list launchpad.net/gocheck can't load package: package launchpad.net/gocheck: unknown import path "launchpad.net/gocheck": bzr branch --use-existing-dir https://launchpad.net/~niemeyer/gocheck/trunk . in /Users/rsc/pkg/mod/cache/vcs/f46ce2ae80d31f9b0a29099baa203e3b6d269dace4e5357a2cf74bd109e13339: exec: "bzr": executable file not found in $PATH $ Fixes #26885. Fixes #26982. Change-Id: I2f9cf1853d2d68af18adad668c80513b6ba220d6 Reviewed-on: https://go-review.googlesource.com/129683 Run-TryBot: Russ Cox <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 4864dec commit 850c964

File tree

5 files changed

+38
-0
lines changed

5 files changed

+38
-0
lines changed

src/cmd/go/internal/modfetch/codehost/vcs.go

+14
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,17 @@ import (
2222
"cmd/go/internal/str"
2323
)
2424

25+
// A VCSError indicates an error using a version control system.
26+
// The implication of a VCSError is that we know definitively where
27+
// to get the code, but we can't access it due to the error.
28+
// The caller should report this error instead of continuing to probe
29+
// other possible module paths.
30+
type VCSError struct {
31+
Err error
32+
}
33+
34+
func (e *VCSError) Error() string { return e.Err.Error() }
35+
2536
func NewRepo(vcs, remote string) (Repo, error) {
2637
type key struct {
2738
vcs string
@@ -33,6 +44,9 @@ func NewRepo(vcs, remote string) (Repo, error) {
3344
}
3445
c := vcsRepoCache.Do(key{vcs, remote}, func() interface{} {
3546
repo, err := newVCSRepo(vcs, remote)
47+
if err != nil {
48+
err = &VCSError{err}
49+
}
3650
return cached{repo, err}
3751
}).(cached)
3852

src/cmd/go/internal/modfetch/repo.go

+3
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,9 @@ func lookup(path string) (r Repo, err error) {
237237
func lookupCodeRepo(rr *get.RepoRoot) (codehost.Repo, error) {
238238
code, err := codehost.NewRepo(rr.VCS, rr.Repo)
239239
if err != nil {
240+
if _, ok := err.(*codehost.VCSError); ok {
241+
return nil, err
242+
}
240243
return nil, fmt.Errorf("lookup %s: %v", rr.Root, err)
241244
}
242245
return code, nil

src/cmd/go/internal/modload/import.go

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"strings"
1515

1616
"cmd/go/internal/cfg"
17+
"cmd/go/internal/modfetch/codehost"
1718
"cmd/go/internal/module"
1819
"cmd/go/internal/par"
1920
"cmd/go/internal/search"
@@ -133,6 +134,9 @@ func Import(path string) (m module.Version, dir string, err error) {
133134

134135
m, _, err = QueryPackage(path, "latest", Allowed)
135136
if err != nil {
137+
if _, ok := err.(*codehost.VCSError); ok {
138+
return module.Version{}, "", err
139+
}
136140
return module.Version{}, "", &ImportMissingError{ImportPath: path}
137141
}
138142
return m, "", &ImportMissingError{ImportPath: path, Module: m}

src/cmd/go/internal/modload/query.go

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package modload
66

77
import (
88
"cmd/go/internal/modfetch"
9+
"cmd/go/internal/modfetch/codehost"
910
"cmd/go/internal/module"
1011
"cmd/go/internal/semver"
1112
"fmt"
@@ -223,6 +224,11 @@ func QueryPackage(path, query string, allowed func(module.Version) bool) (module
223224
for p := path; p != "."; p = pathpkg.Dir(p) {
224225
info, err := Query(p, query, allowed)
225226
if err != nil {
227+
if _, ok := err.(*codehost.VCSError); ok {
228+
// A VCSError means we know where to find the code,
229+
// we just can't. Abort search.
230+
return module.Version{}, nil, err
231+
}
226232
if finalErr == errMissing {
227233
finalErr = err
228234
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[exec:bzr] skip 'tests NOT having bzr'
2+
[!net] skip
3+
4+
env GO111MODULE=on
5+
env GOPROXY=
6+
7+
! go list launchpad.net/gocheck
8+
stderr '"bzr": executable file not found'
9+
10+
-- go.mod --
11+
module m

0 commit comments

Comments
 (0)