Skip to content

Commit

Permalink
cmd/go/internal/get: propagate server errors if no go-import tags are…
Browse files Browse the repository at this point in the history
… found

Updates #30748

Change-Id: Ic93c68c1c4b2728f383edfdb06371ecc79a6f7b1
Reviewed-on: https://go-review.googlesource.com/c/go/+/189779
Run-TryBot: Bryan C. Mills <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Jay Conrod <[email protected]>
  • Loading branch information
Bryan C. Mills committed Sep 11, 2019
1 parent 95e1ea4 commit 2a4c0af
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/cmd/go/internal/get/vcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ func RepoRootForImportPath(importPath string, mod ModuleMode, security web.Secur
if err == errUnknownSite {
rr, err = repoRootForImportDynamic(importPath, mod, security)
if err != nil {
err = fmt.Errorf("unrecognized import path %q (%v)", importPath, err)
err = fmt.Errorf("unrecognized import path %q: %v", importPath, err)
}
}
if err != nil {
Expand Down Expand Up @@ -799,6 +799,13 @@ func repoRootForImportDynamic(importPath string, mod ModuleMode, security web.Se
body := resp.Body
defer body.Close()
imports, err := parseMetaGoImports(body, mod)
if len(imports) == 0 {
if respErr := resp.Err(); respErr != nil {
// If the server's status was not OK, prefer to report that instead of
// an XML parse error.
return nil, respErr
}
}
if err != nil {
return nil, fmt.Errorf("parsing %s: %v", importPath, err)
}
Expand Down Expand Up @@ -909,6 +916,13 @@ func metaImportsForPrefix(importPrefix string, mod ModuleMode, security web.Secu
body := resp.Body
defer body.Close()
imports, err := parseMetaGoImports(body, mod)
if len(imports) == 0 {
if respErr := resp.Err(); respErr != nil {
// If the server's status was not OK, prefer to report that instead of
// an XML parse error.
return setCache(fetchResult{url: url, err: respErr})
}
}
if err != nil {
return setCache(fetchResult{url: url, err: fmt.Errorf("parsing %s: %v", resp.URL, err)})
}
Expand Down Expand Up @@ -962,7 +976,7 @@ func (m ImportMismatchError) Error() string {

// matchGoImport returns the metaImport from imports matching importPath.
// An error is returned if there are multiple matches.
// errNoMatch is returned if none match.
// An ImportMismatchError is returned if none match.
func matchGoImport(imports []metaImport, importPath string) (metaImport, error) {
match := -1

Expand Down

0 comments on commit 2a4c0af

Please sign in to comment.