mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/go: check go version when parsing go.mod fails
Fixes #70979 Change-Id: I6597fe178eed34702eea6cba4eec5174c9203458 Reviewed-on: https://go-review.googlesource.com/c/go/+/639115 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Matloob <matloob@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com>
This commit is contained in:
parent
de9fdc7b71
commit
6da16013ba
2 changed files with 22 additions and 0 deletions
|
|
@ -44,6 +44,17 @@ func ReadModFile(gomod string, fix modfile.VersionFixer) (data []byte, f *modfil
|
||||||
|
|
||||||
f, err = modfile.Parse(gomod, data, fix)
|
f, err = modfile.Parse(gomod, data, fix)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
f, laxErr := modfile.ParseLax(gomod, data, fix)
|
||||||
|
if laxErr == nil {
|
||||||
|
if f.Go != nil && gover.Compare(f.Go.Version, gover.Local()) > 0 {
|
||||||
|
toolchain := ""
|
||||||
|
if f.Toolchain != nil {
|
||||||
|
toolchain = f.Toolchain.Name
|
||||||
|
}
|
||||||
|
return nil, nil, &gover.TooNewError{What: base.ShortPath(gomod), GoVersion: f.Go.Version, Toolchain: toolchain}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Errors returned by modfile.Parse begin with file:line.
|
// Errors returned by modfile.Parse begin with file:line.
|
||||||
return nil, nil, fmt.Errorf("errors parsing %s:\n%w", base.ShortPath(gomod), shortPathErrorList(err))
|
return nil, nil, fmt.Errorf("errors parsing %s:\n%w", base.ShortPath(gomod), shortPathErrorList(err))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
11
src/cmd/go/testdata/script/mod_unknown_block.txt
vendored
Normal file
11
src/cmd/go/testdata/script/mod_unknown_block.txt
vendored
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
env GOTOOLCHAIN=local
|
||||||
|
! go list .
|
||||||
|
stderr 'go: go.mod requires go >= 1.999'
|
||||||
|
|
||||||
|
|
||||||
|
-- go.mod --
|
||||||
|
module example.com
|
||||||
|
|
||||||
|
go 1.999
|
||||||
|
|
||||||
|
anewblock foo
|
||||||
Loading…
Add table
Add a link
Reference in a new issue