golang/go · error

maximum supported Go version is %s

Error message

maximum supported Go version is %s

What it means

Thrown by goVersionFlag.Set when the provided Go version is structurally valid (passes GoVersionRE) but is higher than the currently running toolchain version (`gover.Local()`). The go command refuses to set a go.mod directive to a version newer than itself, since it cannot guarantee correct behavior. Note that the type comment says it 'intentionally allows newer-than-supported versions as arguments' but this specific check blocks versions strictly greater than the local toolchain.

Source

Thrown at src/cmd/go/internal/modcmd/tidy.go:99

// A goVersionFlag is a flag.Value representing a supported Go version.
//
// (Note that the -go argument to 'go mod edit' is *not* a goVersionFlag.
// It intentionally allows newer-than-supported versions as arguments.)
type goVersionFlag struct {
	v string
}

func (f *goVersionFlag) String() string { return f.v }
func (f *goVersionFlag) Get() any       { return f.v }

func (f *goVersionFlag) Set(s string) error {
	if s != "" {
		latest := gover.Local()
		if !modfile.GoVersionRE.MatchString(s) {
			return fmt.Errorf("expecting a Go version like %q", latest)
		}
		if gover.Compare(s, latest) > 0 {
			return fmt.Errorf("maximum supported Go version is %s", latest)
		}
	}

	f.v = s
	return nil
}

func runTidy(ctx context.Context, cmd *base.Command, args []string) {
	moduleLoader := modload.NewLoader()
	if len(args) > 0 {
		base.Fatalf("go: 'go mod tidy' accepts no arguments")
	}

	// Tidy aims to make 'go test' reproducible for any package in 'all', so we
	// need to include test dependencies. For modules that specify go 1.15 or
	// earlier this is a no-op (because 'all' saturates transitive test
	// dependencies).
	//

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Install or upgrade to the required Go toolchain version, then re-run the command
  2. Use `go mod tidy -go=<latest>` where latest is at or below the installed Go version (shown in the error message)
  3. Set GOTOOLCHAIN to auto-download the needed version: `GOTOOLCHAIN=go1.30.0 auto go mod tidy -go=1.30`

Example fix

// before (with Go 1.22 installed)
go mod tidy -go=1.30
// after
GOTOOLCHAIN=auto go mod tidy -go=1.30
Defensive patterns

Strategy: validation

Validate before calling

import (
    "golang.org/x/mod/gover"
)

func validateGoVersionNotTooNew(s string) error {
    if gover.Compare(s, gover.Local()) > 0 {
        return fmt.Errorf("version %s exceeds local toolchain %s; upgrade Go or use GOTOOLCHAIN=auto", s, gover.Local())
    }
    return nil
}

Prevention

When it happens

Trigger: Running `go mod tidy -go=1.30` when the installed Go toolchain is 1.22. `gover.Compare(s, latest)` returns > 0, triggering the error with the local toolchain's version.

Common situations: Upgrading go.mod to a version after a colleague used a newer Go; running an older Go toolchain on a project that targets a newer version; CI environment with an older Go than the local development machine.

Related errors


AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12). Data as JSON: /api/errors/b72b759792a29dd7. Report an issue: GitHub.