Commit 2a4c0afe authored by Bryan C. Mills's avatar Bryan C. Mills

cmd/go/internal/get: propagate server errors if no go-import tags are found

Updates #30748

Change-Id: Ic93c68c1c4b2728f383edfdb06371ecc79a6f7b1
Reviewed-on: https://go-review.googlesource.com/c/go/+/189779
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarJay Conrod <jayconrod@google.com>
parent 95e1ea45
...@@ -661,7 +661,7 @@ func RepoRootForImportPath(importPath string, mod ModuleMode, security web.Secur ...@@ -661,7 +661,7 @@ func RepoRootForImportPath(importPath string, mod ModuleMode, security web.Secur
if err == errUnknownSite { if err == errUnknownSite {
rr, err = repoRootForImportDynamic(importPath, mod, security) rr, err = repoRootForImportDynamic(importPath, mod, security)
if err != nil { 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 { if err != nil {
...@@ -799,6 +799,13 @@ func repoRootForImportDynamic(importPath string, mod ModuleMode, security web.Se ...@@ -799,6 +799,13 @@ func repoRootForImportDynamic(importPath string, mod ModuleMode, security web.Se
body := resp.Body body := resp.Body
defer body.Close() defer body.Close()
imports, err := parseMetaGoImports(body, mod) 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 { if err != nil {
return nil, fmt.Errorf("parsing %s: %v", importPath, err) return nil, fmt.Errorf("parsing %s: %v", importPath, err)
} }
...@@ -909,6 +916,13 @@ func metaImportsForPrefix(importPrefix string, mod ModuleMode, security web.Secu ...@@ -909,6 +916,13 @@ func metaImportsForPrefix(importPrefix string, mod ModuleMode, security web.Secu
body := resp.Body body := resp.Body
defer body.Close() defer body.Close()
imports, err := parseMetaGoImports(body, mod) 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 { if err != nil {
return setCache(fetchResult{url: url, err: fmt.Errorf("parsing %s: %v", resp.URL, err)}) return setCache(fetchResult{url: url, err: fmt.Errorf("parsing %s: %v", resp.URL, err)})
} }
...@@ -962,7 +976,7 @@ func (m ImportMismatchError) Error() string { ...@@ -962,7 +976,7 @@ func (m ImportMismatchError) Error() string {
// matchGoImport returns the metaImport from imports matching importPath. // matchGoImport returns the metaImport from imports matching importPath.
// An error is returned if there are multiple matches. // 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) { func matchGoImport(imports []metaImport, importPath string) (metaImport, error) {
match := -1 match := -1
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment