mirror of
https://github.com/golang/go
synced 2024-09-25 13:20:13 -06:00
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 <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
4864decf04
commit
850c964be2
@ -22,6 +22,17 @@ import (
|
||||
"cmd/go/internal/str"
|
||||
)
|
||||
|
||||
// A VCSError indicates an error using a version control system.
|
||||
// The implication of a VCSError is that we know definitively where
|
||||
// to get the code, but we can't access it due to the error.
|
||||
// The caller should report this error instead of continuing to probe
|
||||
// other possible module paths.
|
||||
type VCSError struct {
|
||||
Err error
|
||||
}
|
||||
|
||||
func (e *VCSError) Error() string { return e.Err.Error() }
|
||||
|
||||
func NewRepo(vcs, remote string) (Repo, error) {
|
||||
type key struct {
|
||||
vcs string
|
||||
@ -33,6 +44,9 @@ func NewRepo(vcs, remote string) (Repo, error) {
|
||||
}
|
||||
c := vcsRepoCache.Do(key{vcs, remote}, func() interface{} {
|
||||
repo, err := newVCSRepo(vcs, remote)
|
||||
if err != nil {
|
||||
err = &VCSError{err}
|
||||
}
|
||||
return cached{repo, err}
|
||||
}).(cached)
|
||||
|
||||
|
@ -237,6 +237,9 @@ func lookup(path string) (r Repo, err error) {
|
||||
func lookupCodeRepo(rr *get.RepoRoot) (codehost.Repo, error) {
|
||||
code, err := codehost.NewRepo(rr.VCS, rr.Repo)
|
||||
if err != nil {
|
||||
if _, ok := err.(*codehost.VCSError); ok {
|
||||
return nil, err
|
||||
}
|
||||
return nil, fmt.Errorf("lookup %s: %v", rr.Root, err)
|
||||
}
|
||||
return code, nil
|
||||
|
@ -14,6 +14,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"cmd/go/internal/cfg"
|
||||
"cmd/go/internal/modfetch/codehost"
|
||||
"cmd/go/internal/module"
|
||||
"cmd/go/internal/par"
|
||||
"cmd/go/internal/search"
|
||||
@ -133,6 +134,9 @@ func Import(path string) (m module.Version, dir string, err error) {
|
||||
|
||||
m, _, err = QueryPackage(path, "latest", Allowed)
|
||||
if err != nil {
|
||||
if _, ok := err.(*codehost.VCSError); ok {
|
||||
return module.Version{}, "", err
|
||||
}
|
||||
return module.Version{}, "", &ImportMissingError{ImportPath: path}
|
||||
}
|
||||
return m, "", &ImportMissingError{ImportPath: path, Module: m}
|
||||
|
@ -6,6 +6,7 @@ package modload
|
||||
|
||||
import (
|
||||
"cmd/go/internal/modfetch"
|
||||
"cmd/go/internal/modfetch/codehost"
|
||||
"cmd/go/internal/module"
|
||||
"cmd/go/internal/semver"
|
||||
"fmt"
|
||||
@ -223,6 +224,11 @@ func QueryPackage(path, query string, allowed func(module.Version) bool) (module
|
||||
for p := path; p != "."; p = pathpkg.Dir(p) {
|
||||
info, err := Query(p, query, allowed)
|
||||
if err != nil {
|
||||
if _, ok := err.(*codehost.VCSError); ok {
|
||||
// A VCSError means we know where to find the code,
|
||||
// we just can't. Abort search.
|
||||
return module.Version{}, nil, err
|
||||
}
|
||||
if finalErr == errMissing {
|
||||
finalErr = err
|
||||
}
|
||||
|
11
src/cmd/go/testdata/script/mod_vcs_missing.txt
vendored
Normal file
11
src/cmd/go/testdata/script/mod_vcs_missing.txt
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
[exec:bzr] skip 'tests NOT having bzr'
|
||||
[!net] skip
|
||||
|
||||
env GO111MODULE=on
|
||||
env GOPROXY=
|
||||
|
||||
! go list launchpad.net/gocheck
|
||||
stderr '"bzr": executable file not found'
|
||||
|
||||
-- go.mod --
|
||||
module m
|
Loading…
Reference in New Issue
Block a user