Skip to content

Commit

Permalink
cmd/go: check go version when parsing go.mod fails
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
seankhliao authored and matloob committed Jan 13, 2025
1 parent de9fdc7 commit 6da1601
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/cmd/go/internal/modload/modfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ func ReadModFile(gomod string, fix modfile.VersionFixer) (data []byte, f *modfil

f, err = modfile.Parse(gomod, data, fix)
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.
return nil, nil, fmt.Errorf("errors parsing %s:\n%w", base.ShortPath(gomod), shortPathErrorList(err))
}
Expand Down
11 changes: 11 additions & 0 deletions src/cmd/go/testdata/script/mod_unknown_block.txt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 6da1601

Please sign in to comment.