golang/go · error

unrecognized GOEXPERIMENT %q

Error message

unrecognized GOEXPERIMENT %q

What it means

Thrown by the GOEXPERIMENT prefix condition registered by scripttest.AddToolChainScriptConditions (conditions.go:99-116). It parses the current GOEXPERIMENT env via buildcfg.ParseGOEXPERIMENT, then checks the queried value against all enabled flags. If the value matches no flag (even negated via 'no'), it is unrecognized and errors. This catches references to experiments that do not exist for the current GOOS/GOARCH.

Source

Thrown at src/cmd/internal/script/scripttest/conditions.go:115

}

func hasGoexperiment(s *script.State, value string) (bool, error) {
	GOOS, _ := s.LookupEnv("GOOS")
	GOARCH, _ := s.LookupEnv("GOARCH")
	goexp, _ := s.LookupEnv("GOEXPERIMENT")
	flags, err := buildcfg.ParseGOEXPERIMENT(GOOS, GOARCH, goexp)
	if err != nil {
		return false, err
	}
	for _, exp := range flags.All() {
		if value == exp {
			return true, nil
		}
		if strings.TrimPrefix(value, "no") == strings.TrimPrefix(exp, "no") {
			return false, nil
		}
	}
	return false, fmt.Errorf("unrecognized GOEXPERIMENT %q", value)
}

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Consult internal/buildcfg or run with an empty GOEXPERIMENT to list valid flags for the platform.
  2. Remove the condition line if the experiment no longer exists.
  3. Gate experiment-specific tests behind a Go-version check so they do not reference stale names.

Example fix

// before
[GOEXPERIMENT:fieldtrack] exec go build
// after (experiment removed)
[!GOEXPERIMENT:fieldtrack] skip "fieldtrack no longer exists"
// or simply remove the line
Defensive patterns

Strategy: validation

Validate before calling

import "internal/buildcfg"

func validGOEXPERIMENT(goos, goarch, goexp, value string) bool {
    flags, err := buildcfg.ParseGOEXPERIMENT(goos, goarch, goexp)
    if err != nil {
        return false
    }
    for _, exp := range flags.All() {
        if value == exp || strings.TrimPrefix(value, "no") == strings.TrimPrefix(exp, "no") {
            return true
        }
    }
    return false
}

Prevention

When it happens

Trigger: Writing [GOEXPERIMENT:bogusflag] cmd where 'bogusflag' is not a real experiment; referencing an experiment that was renamed or removed in the current Go version; using an experiment not valid for the target GOOS/GOARCH.

Common situations: Experiment dropped between Go releases (e.g. fieldtrack, regabi in transition); typo in the experiment name; experiment only available on specific architectures.

Related errors


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