golang/go · error

unknown condition

Error message

unknown condition %q

What it means

Thrown by Engine.conditionsActive when a condition bracket has no colon but the tag is not in e.Conds (engine.go:527-530). Unlike the prefix variant this message does not list known conditions. It means the bare condition name was never registered.

Solutions

  1. Check spelling and case against the registered condition names (conditions are case-sensitive).
  2. Ensure DefaultConds() and any needed AddToolChainScriptConditions populate e.Conds.
  3. Register the custom condition under the exact tag used in the bracket.

Example fix

// before
[CGO] exec go build
// after
[cgo] exec go build
Defensive patterns

Strategy: validation

Validate before calling

func condKnown(conds map[string]script.Cond, tag string) bool {
    _, ok := conds[tag]
    return ok
}

Prevention

When it happens

Trigger: Writing [unknowntag] cmd where unknowntag is not a key in e.Conds; using [CGO] (wrong case — conditions are case-sensitive) instead of [cgo]; referencing an unregistered custom condition.

Common situations: Case mismatch (CGO vs cgo); typo; condition not registered because AddToolChainScriptConditions or DefaultConds was not called; condition exists only in a different engine configuration.

Related errors


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

Appendix: source

Thrown at src/cmd/internal/script/engine.go:529

	return b.String()
}

func (e *Engine) conditionsActive(s *State, conds []condition) (bool, error) {
	for _, cond := range conds {
		var impl Cond
		prefix, suffix, ok := strings.Cut(cond.tag, ":")
		if ok {
			impl = e.Conds[prefix]
			if impl == nil {
				return false, fmt.Errorf("unknown condition prefix %q; known: %v", prefix, slices.Collect(maps.Keys(e.Conds)))
			}
			if !impl.Usage().Prefix {
				return false, fmt.Errorf("condition %q cannot be used with a suffix", prefix)
			}
		} else {
			impl = e.Conds[cond.tag]
			if impl == nil {
				return false, fmt.Errorf("unknown condition %q", cond.tag)
			}
			if impl.Usage().Prefix {
				return false, fmt.Errorf("condition %q requires a suffix", cond.tag)
			}
		}
		active, err := impl.Eval(s, suffix)

		if err != nil {
			return false, fmt.Errorf("evaluating condition %q: %w", cond.tag, err)
		}
		if active != cond.want {
			return false, nil
		}
	}

	return true, nil
}

View on GitHub (pinned to b6b368adc5)