@@ -661,7 +661,7 @@ func RepoRootForImportPath(importPath string, mod ModuleMode, security web.Secur
661
661
if err == errUnknownSite {
662
662
rr , err = repoRootForImportDynamic (importPath , mod , security )
663
663
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 )
665
665
}
666
666
}
667
667
if err != nil {
@@ -799,6 +799,13 @@ func repoRootForImportDynamic(importPath string, mod ModuleMode, security web.Se
799
799
body := resp .Body
800
800
defer body .Close ()
801
801
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
+ }
802
809
if err != nil {
803
810
return nil , fmt .Errorf ("parsing %s: %v" , importPath , err )
804
811
}
@@ -909,6 +916,13 @@ func metaImportsForPrefix(importPrefix string, mod ModuleMode, security web.Secu
909
916
body := resp .Body
910
917
defer body .Close ()
911
918
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
+ }
912
926
if err != nil {
913
927
return setCache (fetchResult {url : url , err : fmt .Errorf ("parsing %s: %v" , resp .URL , err )})
914
928
}
@@ -962,7 +976,7 @@ func (m ImportMismatchError) Error() string {
962
976
963
977
// matchGoImport returns the metaImport from imports matching importPath.
964
978
// An error is returned if there are multiple matches.
965
- // errNoMatch is returned if none match.
979
+ // An ImportMismatchError is returned if none match.
966
980
func matchGoImport (imports []metaImport , importPath string ) (metaImport , error ) {
967
981
match := - 1
968
982
0 commit comments