GoogleContainerTools/skaffold · error
invalid exclude patterns: %w
Error message
invalid exclude patterns: %w
What it means
NewDockerIgnorePredicate compiles the exclude patterns (from .dockerignore or skaffold config) into a docker patternmatcher. If patternmatcher.New fails, the patterns are syntactically invalid and this error wraps the parser message. WalkWorkspace and walkWorkspaceWithDestinations call it, so an invalid pattern aborts dependency calculation before any walking starts.
Source
Thrown at pkg/skaffold/docker/dockerignore.go:34
package docker
import (
"fmt"
"path/filepath"
"strings"
"github.com/moby/patternmatcher"
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/walk"
)
// NewDockerIgnorePredicate creates a walk.Predicate that checks if directory entries
// should be ignored.
func NewDockerIgnorePredicate(workspace string, excludes []string) (walk.Predicate, error) {
matcher, err := patternmatcher.New(excludes)
if err != nil {
return nil, fmt.Errorf("invalid exclude patterns: %w", err)
}
return func(path string, info walk.Dirent) (bool, error) {
relPath, err := filepath.Rel(workspace, path)
if err != nil {
return false, err
}
ignored, err := matcher.MatchesOrParentMatches(relPath)
if err != nil {
return false, err
}
if ignored && info.IsDir() && skipDir(relPath, matcher) {
return false, filepath.SkipDir
}
return ignored, nil
}, nilView on GitHub (pinned to a1189de023)
Solutions
- Read the wrapped patternmatcher error to identify the offending pattern and fix its syntax in .dockerignore (or the excludes list in skaffold.yaml).
- Test patterns with a minimal `docker build` in the same directory — Docker reports the same invalid .dockerignore line.
- Remove or comment out the suspicious line; re-add patterns incrementally until the parser accepts them.
- Ensure each pattern is a valid dockerignore glob (no unterminated [..] classes, no malformed ! exceptions).
Example fix
# before (.dockerignore) build/[temp # after (.dockerignore) build/temp
Defensive patterns
Strategy: validation
Validate before calling
// Go: validate exclude patterns before calling NewDockerIgnorePredicate
func validExcludePatterns(pats []string) error {
for _, p := range pats {
if strings.TrimSpace(p) == "" { continue }
if strings.Count(p, "[") != strings.Count(p, "]") {
return fmt.Errorf("unbalanced bracket in pattern %q", p)
}
}
return nil
} Try / catch
pred, err := docker.NewDockerIgnorePredicate(workspace, excludes)
if err != nil {
return fmt.Errorf("check .dockerignore / skaffold excludes: %w", err)
} Prevention
- Lint .dockerignore patterns in CI (test-compile them with patternmatcher or a docker build).
- Copy patterns only from dockerignore-syntax references, not other glob dialects.
- Keep one canonical .dockerignore per artifact workspace and review edits.
- Strip BOM/whitespace when generating exclude lists programmatically.
When it happens
Trigger: Calling NewDockerIgnorePredicate(workspace, excludes) with malformed exclude globs — e.g. an unterminated character class like "[abc", invalid syntax patternmatcher rejects, or a bad regex-style expression — usually supplied via .dockerignore or artifact excludes in skaffold.yaml.
Common situations: Hand-edited .dockerignore with a typo like `**[ [` or stray `[`; exclude lines copied from another tool that uses different glob syntax; trailing whitespace or control characters in .dockerignore introduced by editors or CRLF mishaps in edge cases.
Related errors
- %s is an invalid api version
- empty minikube profile
- unknown update strategy %q
- cannot add an empty image value
- value must be one of `always`, `missing`, or `never`
AI-assisted analysis of GoogleContainerTools/skaffold@a1189de023 (2026-09-05).
Data as JSON: /api/errors/c22327e4461cfea8.
Report an issue: GitHub.