golang/go · error

unrecognized GOOS %q

Error message

unrecognized GOOS %q

What it means

Thrown by the script engine's built-in GOOS prefix condition (registered via PrefixCondition in DefaultConds). When a script uses [GOOS:<suffix>] and the suffix neither equals runtime.GOOS nor appears in internal/syslist.KnownOS, the condition cannot be evaluated meaningfully, so it errors rather than silently returning false. This catches typos in OS names so test authors do not accidentally skip lines on every platform.

Source

Thrown at src/cmd/internal/script/conds.go:29

	"runtime"
	"sync"
)

// DefaultConds returns a set of broadly useful script conditions.
//
// Run the 'help' command within a script engine to view a list of the available
// conditions.
func DefaultConds() map[string]Cond {
	conds := make(map[string]Cond)

	conds["GOOS"] = PrefixCondition(
		"runtime.GOOS == <suffix>",
		func(_ *State, suffix string) (bool, error) {
			if suffix == runtime.GOOS {
				return true, nil
			}
			if _, ok := syslist.KnownOS[suffix]; !ok {
				return false, fmt.Errorf("unrecognized GOOS %q", suffix)
			}
			return false, nil
		})

	conds["GOARCH"] = PrefixCondition(
		"runtime.GOARCH == <suffix>",
		func(_ *State, suffix string) (bool, error) {
			if suffix == runtime.GOARCH {
				return true, nil
			}
			if _, ok := syslist.KnownArch[suffix]; !ok {
				return false, fmt.Errorf("unrecognized GOARCH %q", suffix)
			}
			return false, nil
		})

	conds["compiler"] = PrefixCondition(
		"runtime.Compiler == <suffix>",

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Correct the suffix to a valid Go GOOS value (e.g. linux, darwin, windows, freebsd) — consult internal/syslist.KnownOS for the complete accepted set.
  2. Run the 'help' command inside the script engine to see registered conditions and their summaries.
  3. If the test should skip on every platform, use a deliberately-false-but-recognized value rather than an unknown one.

Example fix

// before
[GOOS:linnux] exec go build
// after
[GOOS:linux] exec go build
Defensive patterns

Strategy: validation

Validate before calling

// Before relying on a GOOS condition suffix, confirm it is a known Go OS.
import "internal/syslist"

func validGOOS(v string) bool {
    _, ok := syslist.KnownOS[v]
    return ok
}

// Use when programmatically generating script condition tags:
//   suffix := "linux"
//   if !validGOOS(suffix) { t.Fatalf("bad GOOS %q", suffix) }

Prevention

When it happens

Trigger: Writing a condition bracket with a misspelled or non-Go OS name, e.g. [GOOS:linnux], [GOOS:macos], or [GOOS:unix]. The eval function in conds.go:24-32 is invoked when the script engine evaluates the bracketed condition before a command.

Common situations: Typo in a test script condition; copy-pasting an OS alias that Go does not recognize (e.g. 'macos' instead of 'darwin'); using a vendor-specific name not in Go's target list after a Go upgrade that renamed/removed a port.

Related errors


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