GoogleContainerTools/skaffold · error

pattern error for %q: %w

Error message

pattern error for %q: %w

What it means

During inferred sync, each relative path is tested against the user's `sync.infer` glob patterns with doublestar.PathMatch. If a pattern itself is malformed (e.g. unclosed `[` or `{`), PathMatch returns a syntax error and Skaffold reports it as a pattern error for the file being matched.

Source

Thrown at pkg/skaffold/sync/sync.go:146

	}

	syncMap, err := SyncMap(ctx, a, cfg)
	if err != nil {
		return nil, fmt.Errorf("inferring syncmap for image %q: %w", a.ImageName, err)
	}

	toCopy := make(map[string][]string)
	for _, f := range append(e.Modified, e.Added...) {
		relPath, err := filepath.Rel(a.Workspace, f)
		if err != nil {
			return nil, fmt.Errorf("finding changed file %s relative to context %q: %w", f, a.Workspace, err)
		}

		matches := false
		for _, p := range a.Sync.Infer {
			matches, err = doublestar.PathMatch(filepath.FromSlash(p), relPath)
			if err != nil {
				return nil, fmt.Errorf("pattern error for %q: %w", relPath, err)
			}
			if matches {
				break
			}
		}
		if !matches {
			log.Entry(ctx).Infof("Changed file %s does not match any sync pattern. Skipping sync", relPath)
			return nil, nil
		}

		if dsts, ok := syncMap[relPath]; ok {
			toCopy[f] = dsts
		} else {
			log.Entry(ctx).Infof("Changed file %s is not syncable. Skipping sync", relPath)
			return nil, nil
		}
	}

View on GitHub (pinned to a1189de023)

Solutions

  1. Open skaffold.yaml and fix the malformed `sync.infer` glob (close `[...]`/`{...}` groups)
  2. Validate each pattern locally with doublestar.PathMatch or filepath.Match in a scratch Go program, feeding the relPath shown in the error
  3. Escape literal `[` or `{` in filenames with a `[[]` class instead of the raw character

Example fix

// before
sync:
  infer:
    - src/**/*.go{1   # unbalanced {   
// after
sync:
  infer:
    - src/**/*.go
Defensive patterns

Strategy: validation

Validate before calling

for _, p := range a.Sync.Infer {
    if _, err := doublestar.PathMatch(filepath.FromSlash(p), "sample.go"); err != nil {
        return fmt.Errorf("invalid sync.infer pattern %q: %w", p, err)
    }
}

Type guard

func validGlob(p string) bool {
    _, err := doublestar.PathMatch(filepath.FromSlash(p), "")
    return err == nil
}

Try / catch

item, err := sync.NewItem(ctx, a, tag, e, cfg, builds)
if err != nil {
    if strings.Contains(err.Error(), "pattern error") {
        return fmt.Errorf("fix sync.infer glob in skaffold.yaml: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: A `sync.infer` pattern in skaffold.yaml contains invalid glob syntax — typically an unclosed character class `[`, an unbalanced alternation `{`, or a misplaced `**` — so doublestar.PathMatch errors while matching a changed file's relative path.

Common situations: Hand-edited skaffold.yaml infer patterns like `src/**/*.go{1}` or `src/[a-*.go`; patterns copied from Windows shells where `[` was intended literally; templating that injects a half-written glob.

Related errors


AI-assisted analysis of GoogleContainerTools/skaffold@a1189de023 (2026-09-05). Data as JSON: /api/errors/768e77126167ad99. Report an issue: GitHub.