Skip to content

Commit 2a4c0af

Browse files
author
Bryan C. Mills
committed
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Jay Conrod <[email protected]>
1 parent 95e1ea4 commit 2a4c0af

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/cmd/go/internal/get/vcs.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ func RepoRootForImportPath(importPath string, mod ModuleMode, security web.Secur
661661
if err == errUnknownSite {
662662
rr, err = repoRootForImportDynamic(importPath, mod, security)
663663
if err != nil {
664-
err = fmt.Errorf("unrecognized import path %q (%v)", importPath, err)
664+
err = fmt.Errorf("unrecognized import path %q: %v", importPath, err)
665665
}
666666
}
667667
if err != nil {
@@ -799,6 +799,13 @@ func repoRootForImportDynamic(importPath string, mod ModuleMode, security web.Se
799799
body := resp.Body
800800
defer body.Close()
801801
imports, err := parseMetaGoImports(body, mod)
802+
if len(imports) == 0 {
803+
if respErr := resp.Err(); respErr != nil {
804+
// If the server's status was not OK, prefer to report that instead of
805+
// an XML parse error.
806+
return nil, respErr
807+
}
808+
}
802809
if err != nil {
803810
return nil, fmt.Errorf("parsing %s: %v", importPath, err)
804811
}
@@ -909,6 +916,13 @@ func metaImportsForPrefix(importPrefix string, mod ModuleMode, security web.Secu
909916
body := resp.Body
910917
defer body.Close()
911918
imports, err := parseMetaGoImports(body, mod)
919+
if len(imports) == 0 {
920+
if respErr := resp.Err(); respErr != nil {
921+
// If the server's status was not OK, prefer to report that instead of
922+
// an XML parse error.
923+
return setCache(fetchResult{url: url, err: respErr})
924+
}
925+
}
912926
if err != nil {
913927
return setCache(fetchResult{url: url, err: fmt.Errorf("parsing %s: %v", resp.URL, err)})
914928
}
@@ -962,7 +976,7 @@ func (m ImportMismatchError) Error() string {
962976

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

0 commit comments

Comments
 (0)