The signature of parseMetaGoImports implies that it can return an error,
but it has not done so since CL 119675. Restore the missing error check,
and remove the named return-values to avoid reintroducing this bug in the
future.
Updates #30748
Updates #21291
Change-Id: Iab19ade5b1c23c282f3c385a55ed277465526515
Reviewed-on: https://go-review.googlesource.com/c/go/+/189778
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
// parseMetaGoImports returns meta imports from the HTML in r.
// Parsing ends at the end of the <head> section or the beginning of the <body>.
-func parseMetaGoImports(r io.Reader, mod ModuleMode) (imports []metaImport, err error) {
+func parseMetaGoImports(r io.Reader, mod ModuleMode) ([]metaImport, error) {
d := xml.NewDecoder(r)
d.CharsetReader = charsetReader
d.Strict = false
- var t xml.Token
+ var imports []metaImport
for {
- t, err = d.RawToken()
+ t, err := d.RawToken()
if err != nil {
- if err == io.EOF || len(imports) > 0 {
- err = nil
+ if err != io.EOF && len(imports) == 0 {
+ return nil, err
}
break
}