golang/go · error

unreachable pattern in GOVCS: %q after %q

Error message

unreachable pattern in GOVCS: %q after %q

What it means

GOVCS rules are evaluated in order and the first match wins. If the same pattern appears twice, the second occurrence is unreachable because the first already matched every request for that pattern. The parser detects this duplicate and rejects it.

Source

Thrown at src/cmd/go/internal/vcs/vcs.go:655

		if item == "" {
			return nil, fmt.Errorf("empty entry in GOVCS")
		}
		pattern, list, found := strings.Cut(item, ":")
		if !found {
			return nil, fmt.Errorf("malformed entry in GOVCS (missing colon): %q", item)
		}
		pattern, list = strings.TrimSpace(pattern), strings.TrimSpace(list)
		if pattern == "" {
			return nil, fmt.Errorf("empty pattern in GOVCS: %q", item)
		}
		if list == "" {
			return nil, fmt.Errorf("empty VCS list in GOVCS: %q", item)
		}
		if search.IsRelativePath(pattern) {
			return nil, fmt.Errorf("relative pattern not allowed in GOVCS: %q", pattern)
		}
		if old := have[pattern]; old != "" {
			return nil, fmt.Errorf("unreachable pattern in GOVCS: %q after %q", item, old)
		}
		have[pattern] = item
		allowed := strings.Split(list, "|")
		for i, a := range allowed {
			a = strings.TrimSpace(a)
			if a == "" {
				return nil, fmt.Errorf("empty VCS name in GOVCS: %q", item)
			}
			allowed[i] = a
		}
		cfg = append(cfg, govcsRule{pattern, allowed})
	}
	return cfg, nil
}

func (c *govcsConfig) allow(path string, private bool, vcs string) bool {
	for _, rule := range *c {
		match := false

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Consolidate duplicate patterns into a single entry with a combined VCS list: `public:git|hg`
  2. Remove the later duplicate entry
  3. Review the full GOVCS value for repeated patterns

Example fix

# before: duplicate 'public' pattern
export GOVCS="public:git,public:hg"

# after: single entry with combined VCS list
export GOVCS="public:git|hg"
Defensive patterns

Strategy: validation

Validate before calling

# Check for duplicate GOVCS patterns
GOVCS_VAL="${GOVCS:-}"
if [ -n "$GOVCS_VAL" ]; then
  echo "$GOVCS_VAL" | tr ',' '\n' | while IFS= read -r entry; do
    echo "$(echo "${entry%%:*}" | xargs)"
  done | sort | uniq -d | while read -r dup; do
    [ -n "$dup" ] && echo "ERROR: duplicate GOVCS pattern: $dup"
  done
fi

Prevention

When it happens

Trigger: GOVCS contains the same pattern twice: `GOVCS=public:git,public:hg` — the second 'public' rule is shadowed by the first.

Common situations: Appending to GOVCS without checking for existing entries; merging multiple config sources that both define the same pattern.

Related errors


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