golang/go · error

missing <pattern> in <pattern>=<value>

Error message

missing <pattern> in <pattern>=<value>

What it means

The per-package flag parser found '=' at position 0 of the trimmed value, meaning the pattern (left side of '=') is empty. A non-empty pattern is required to know which packages the flags should apply to. This is a distinct error from a missing '=' entirely — here the '=' exists but nothing precedes it.

Source

Thrown at src/cmd/go/internal/load/flag.go:61

func (f *PerPackageFlag) set(v, cwd string) error {
	f.raw = v
	f.present = true
	match := func(_ *modload.Loader, p *Package) bool { return p.Internal.CmdlinePkg || p.Internal.CmdlineFiles } // default predicate with no pattern
	// For backwards compatibility with earlier flag splitting, ignore spaces around flags.
	v = strings.TrimSpace(v)
	if v == "" {
		// Special case: -gcflags="" means no flags for command-line arguments
		// (overrides previous -gcflags="-whatever").
		f.values = append(f.values, ppfValue{match, []string{}})
		return nil
	}
	if !strings.HasPrefix(v, "-") {
		i := strings.Index(v, "=")
		if i < 0 {
			return fmt.Errorf("missing =<value> in <pattern>=<value>")
		}
		if i == 0 {
			return fmt.Errorf("missing <pattern> in <pattern>=<value>")
		}
		if v[0] == '\'' || v[0] == '"' {
			return fmt.Errorf("parameter may not start with quote character %c", v[0])
		}
		pattern := strings.TrimSpace(v[:i])
		match = MatchPackage(pattern, cwd)
		v = v[i+1:]
	}
	flags, err := quoted.Split(v)
	if err != nil {
		return err
	}
	if flags == nil {
		flags = []string{}
	}
	f.values = append(f.values, ppfValue{match, flags})
	return nil
}

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Provide a non-empty pattern before the '=': use '.' for the current directory or './...' for all packages.
  2. Alternatively, if you want flags for all command-line packages, use the leading '-' form: -gcflags="-N -l".
  3. Check for accidental double '=' in shell commands.

Example fix

// before — empty pattern (value starts with =)
go build -gcflags=="-N -l"
// after — valid non-empty pattern
go build -gcflags=".=-N -l"
Defensive patterns

Strategy: validation

Validate before calling

// Check that pattern is non-empty when using pattern=value form.
func validatePerPackageFlag(v string) error {
    v = strings.TrimSpace(v)
    if v == "" || strings.HasPrefix(v, "-") {
        return nil
    }
    i := strings.Index(v, "=")
    if i < 0 {
        return fmt.Errorf("missing =<value>: %q", v)
    }
    if i == 0 {
        return fmt.Errorf("missing <pattern> before =: %q", v)
    }
    return nil
}

Prevention

When it happens

Trigger: Passing -gcflags=="-N -l" (double =, so the value starts with =) or -ldflags==-s -w. The strings.Index returns 0, indicating the pattern portion before '=' is empty.

Common situations: Typos in shell commands producing a leading '='. Accidental double '=' from copy-pasting. Misunderstanding that an empty pattern is invalid — use a leading '-' on the flags instead for command-line packages.

Related errors


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