{"record":{"id":"e1ecc4d5d11c3940","repo":"twpayne/chezmoi","slug":"s-invalid-pattern","errorCode":null,"errorMessage":"%s: invalid pattern","messagePattern":"(.+?): invalid pattern","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/chezmoi/patternset.go","lineNumber":48,"sourceCode":"\n// An PatternSet is a set of patterns.\ntype PatternSet struct {\n\tIncludePatterns chezmoiset.Set[string]\n\tExcludePatterns chezmoiset.Set[string]\n}\n\n// NewPatternSet returns a new patternSet.\nfunc NewPatternSet() *PatternSet {\n\treturn &PatternSet{\n\t\tIncludePatterns: chezmoiset.New[string](),\n\t\tExcludePatterns: chezmoiset.New[string](),\n\t}\n}\n\n// Add adds a pattern to ps.\nfunc (ps *PatternSet) Add(pattern string, include PatternSetIncludeType) error {\n\tif ok := doublestar.ValidatePattern(pattern); !ok {\n\t\treturn fmt.Errorf(\"%s: invalid pattern\", pattern)\n\t}\n\tswitch include {\n\tcase PatternSetInclude:\n\t\tps.IncludePatterns.Add(pattern)\n\tcase PatternSetExclude:\n\t\tps.ExcludePatterns.Add(pattern)\n\t}\n\treturn nil\n}\n\n// Glob returns all matches in fileSystem.\nfunc (ps *PatternSet) Glob(fileSystem vfs.FS, prefix string) ([]string, error) {\n\tallMatches := chezmoiset.New[string]()\n\tfor includePattern := range ps.IncludePatterns {\n\t\tmatches, err := Glob(fileSystem, filepath.ToSlash(prefix+includePattern))\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/twpayne/chezmoi/blob/f901167e4685db90da56d6a2a19df642cb3e0247/internal/chezmoi/patternset.go#L30-L66","documentation":"PatternSet.Add validates each pattern with doublestar.ValidatePattern before adding it to the include or exclude sets. If the pattern is not valid doublestar glob syntax, the pattern is rejected with this error naming the pattern. This catches malformed globs early instead of failing during matching.","triggerScenarios":"Calling Add (via mustNewPatternSet, addPatterns, or readExternalArchive) with a pattern containing invalid glob syntax, e.g. unclosed '[', bad '**' placement, or stray characters doublestar rejects.","commonSituations":"Hand-edited .chezmoiignore patterns, copy-pasted globs from other tools with unsupported syntax, unbalanced character classes like '[a-' in ignore patterns.","solutions":["Fix the pattern to valid doublestar glob syntax (balance [], escape literals with \\\\)","Test the pattern with doublestar.ValidatePattern or a glob tester before adding","Remove or comment out the offending pattern to isolate which one is invalid"],"exampleFix":"// before\npatternSet.Add(\"[a-.md\", PatternSetInclude) // unbalanced class\n\n// after\npatternSet.Add(\"[a-z]*.md\", PatternSetInclude)","handlingStrategy":"validation","validationCode":"if !doublestar.ValidatePattern(pattern) {\n    return fmt.Errorf(\"rejecting invalid pattern %q\", pattern)\n}","typeGuard":null,"tryCatchPattern":"if err := ps.Add(pattern, include); err != nil {\n    if strings.Contains(err.Error(), \"invalid pattern\") {\n        // log pattern and skip it instead of aborting\n    }\n}","preventionTips":["Validate all ignore/pattern globs with doublestar.ValidatePattern before use","Escape special glob characters in literal names","Test patterns against sample paths before deploying to .chezmoiignore"],"tags":["go","glob","pattern","validation"],"backgroundTag":"invalid-glob-pattern","analyzedSha":"f901167e4685db90da56d6a2a19df642cb3e0247","analyzedAt":"2026-09-01T18:16:41.508Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T01:17:15.007Z"}