golang/go · error

unknown condition prefix %q

Error message

unknown condition prefix %q

What it means

Thrown by Engine.ListConds when one of the tag arguments contains a colon but the prefix is not in e.Conds (engine.go:732-736). Unlike conditionsActive's variant (1304), this message does not append the list of known conditions. ListConds is the function behind the script 'help'-style listing of conditions.

Source

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

//
// Each of the tag arguments should be a condition string of
// the form "name" or "name:suffix". If no tags are passed as
// arguments, ListConds lists all conditions registered in
// the engine e.
func (e *Engine) ListConds(w io.Writer, s *State, tags ...string) error {
	if tags == nil {
		tags = make([]string, 0, len(e.Conds))
		for name := range e.Conds {
			tags = append(tags, name)
		}
		sort.Strings(tags)
	}

	for _, tag := range tags {
		if prefix, suffix, ok := strings.Cut(tag, ":"); ok {
			cond := e.Conds[prefix]
			if cond == nil {
				return fmt.Errorf("unknown condition prefix %q", prefix)
			}
			usage := cond.Usage()
			if !usage.Prefix {
				return fmt.Errorf("condition %q cannot be used with a suffix", prefix)
			}

			activeStr := ""
			if s != nil {
				if active, _ := cond.Eval(s, suffix); active {
					activeStr = " (active)"
				}
			}
			_, err := fmt.Fprintf(w, "[%s]%s\n\t%s\n", tag, activeStr, usage.Summary)
			if err != nil {
				return err
			}
			continue
		}

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Pass only registered condition tags to ListConds, or pass no tags to list all.
  2. Register the missing condition in e.Conds before listing.
  3. Validate tags against maps.Keys(e.Conds) before calling ListConds.

Example fix

// before
engine.ListConds(w, s, "GOOSX:linux")
// after
engine.ListConds(w, s, "GOOS:linux")
Defensive patterns

Strategy: validation

Validate before calling

import "maps"

func validateListCondsTags(conds map[string]script.Cond, tags []string) error {
    for _, tag := range tags {
        if prefix, _, ok := strings.Cut(tag, ":"); ok {
            if _, ok := conds[prefix]; !ok {
                return fmt.Errorf("unknown condition prefix %q; known: %v", prefix, maps.Keys(conds))
            }
        } else if _, ok := conds[tag]; !ok {
            return fmt.Errorf("unknown condition %q; known: %v", tag, maps.Keys(conds))
        }
    }
    return nil
}

Prevention

When it happens

Trigger: Calling engine.ListConds(w, s, "UNKNOWN:suffix") where UNKNOWN is unregistered; passing a typo'd prefix to the listing helper.

Common situations: Programmatic call to ListConds with an invalid tag; condition unregistered in the engine passed to ListConds; refactoring that renamed a condition without updating callers.

Related errors


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