Skip to content

Commit 109bd90

Browse files
authored
Merge pull request github#14161 from github/mbg/go/add-toolchain-directive-diagnostic
Go: Add diagnostic for 1.21 `toolchain` error
2 parents 7705f0e + 3b70899 commit 109bd90

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

go/extractor/diagnostics/diagnostics.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,3 +482,14 @@ func EmitGoModVersionSupportedLowerEqualGoEnv(msg string) {
482482
noLocation,
483483
)
484484
}
485+
486+
func EmitNewerSystemGoRequired(requiredVersion string) {
487+
emitDiagnostic(
488+
"go/autobuilder/newer-system-go-version-required",
489+
"The Go version installed on the system is too old to support this project",
490+
"At least Go version `"+requiredVersion+"` is required to build this project, but the version installed on the system is older. [Install a newer version](https://github.com/actions/setup-go#basic).",
491+
severityError,
492+
fullVisibility,
493+
noLocation,
494+
)
495+
}

go/extractor/extractor.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ func ExtractWithFlags(buildFlags []string, patterns []string) error {
9191
}
9292
pkgs, err := packages.Load(cfg, patterns...)
9393
if err != nil {
94+
// the toolchain directive is only supported in Go 1.21 and above
95+
if strings.Contains(err.Error(), "unknown directive: toolchain") {
96+
diagnostics.EmitNewerSystemGoRequired("1.21.0")
97+
}
9498
return err
9599
}
96100
log.Println("Done running packages.Load.")

0 commit comments

Comments
 (0)