{"record":{"id":"c22327e4461cfea8","repo":"GoogleContainerTools/skaffold","slug":"invalid-exclude-patterns-w","errorCode":null,"errorMessage":"invalid exclude patterns: %w","messagePattern":"invalid exclude patterns: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/docker/dockerignore.go","lineNumber":34,"sourceCode":"\npackage docker\n\nimport (\n\t\"fmt\"\n\t\"path/filepath\"\n\t\"strings\"\n\n\t\"github.com/moby/patternmatcher\"\n\n\t\"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/walk\"\n)\n\n// NewDockerIgnorePredicate creates a walk.Predicate that checks if directory entries\n// should be ignored.\nfunc NewDockerIgnorePredicate(workspace string, excludes []string) (walk.Predicate, error) {\n\tmatcher, err := patternmatcher.New(excludes)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"invalid exclude patterns: %w\", err)\n\t}\n\n\treturn func(path string, info walk.Dirent) (bool, error) {\n\t\trelPath, err := filepath.Rel(workspace, path)\n\t\tif err != nil {\n\t\t\treturn false, err\n\t\t}\n\t\tignored, err := matcher.MatchesOrParentMatches(relPath)\n\t\tif err != nil {\n\t\t\treturn false, err\n\t\t}\n\n\t\tif ignored && info.IsDir() && skipDir(relPath, matcher) {\n\t\t\treturn false, filepath.SkipDir\n\t\t}\n\n\t\treturn ignored, nil\n\t}, nil","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/docker/dockerignore.go#L16-L52","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)."],"exampleFix":"# before (.dockerignore)\nbuild/[temp\n\n# after (.dockerignore)\nbuild/temp\n","handlingStrategy":"validation","validationCode":"// Go: validate exclude patterns before calling NewDockerIgnorePredicate\nfunc validExcludePatterns(pats []string) error {\n    for _, p := range pats {\n        if strings.TrimSpace(p) == \"\" { continue }\n        if strings.Count(p, \"[\") != strings.Count(p, \"]\") {\n            return fmt.Errorf(\"unbalanced bracket in pattern %q\", p)\n        }\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"pred, err := docker.NewDockerIgnorePredicate(workspace, excludes)\nif err != nil {\n    return fmt.Errorf(\"check .dockerignore / skaffold excludes: %w\", err)\n}","preventionTips":["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."],"tags":["dockerignore","glob","configuration","validation"],"backgroundTag":"invalid-glob-pattern","analyzedSha":"a1189de023efc32d4b8e11f395acc678aa555011","analyzedAt":"2026-09-05T12:09:27.064Z","contentChangedAt":"2026-09-05T12:09:27.064Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}