{"record":{"id":"1409315c7ce9e963","repo":"kubernetes/kops","slug":"unable-to-expand-the-snippets-s-error-s","errorCode":null,"errorMessage":"unable to expand the snippets: %s, error: %s","messagePattern":"unable to expand the snippets: (.+?), error: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kops/toolbox_template.go","lineNumber":156,"sourceCode":"\t\t}\n\t\treturn nil\n\t}\n\n\t// @step: expand the list of templates into a list of files to render\n\tvar templates []string\n\tfor _, x := range options.templatePath {\n\t\tlist, err := expandFiles(utils.ExpandPath(x))\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"unable to expand the template: %s, error: %s\", x, err)\n\t\t}\n\t\ttemplates = append(templates, list...)\n\t}\n\n\tsnippets := make(map[string]string)\n\tfor _, x := range options.snippetsPath {\n\t\tlist, err := expandFiles(utils.ExpandPath(x))\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"unable to expand the snippets: %s, error: %s\", x, err)\n\t\t}\n\n\t\tfor _, j := range list {\n\t\t\tcontent, err := os.ReadFile(j)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"unable to read snippet: %s, error: %s\", j, err)\n\t\t\t}\n\t\t\tsnippets[path.Base(j)] = string(content)\n\t\t}\n\t}\n\n\tchannel, err := kopsapi.LoadChannel(f.VFSContext(), options.channel)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error loading channel %q: %v\", options.channel, err)\n\t}\n\n\t// @step: render each of the templates, splitting on the documents\n\tr := templater.NewTemplater(channel)","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops/toolbox_template.go#L138-L174","documentation":"Returned by RunToolBoxTemplate when expandFiles() fails on one of the --snippets-path entries. Like the template path, the snippet path is ~-expanded then glob-expanded; failure means the snippet path/glob is invalid, matches nothing, or cannot be read. It wraps the underlying filesystem error with the offending path.","triggerScenarios":"`kops toolbox template --snippets-path ./snippets` where the directory doesn't exist, the glob matches zero files, permissions deny access, or expandFiles hits an OS error reading the path.","commonSituations":"Wrong working directory so relative snippet paths don't exist; snippets folder renamed or not committed; typo in --snippets-path; glob syntax misunderstanding (e.g. expecting recursive matching without **).","solutions":["Verify each --snippets-path value exists and matches files from the command's working directory","Use an absolute path or correct the relative path; confirm with `ls <path>`","Check read permissions on the snippets directory","If snippets are optional, remove the --snippets-path flag instead of pointing at an empty/missing location"],"exampleFix":"// before\nkops toolbox template --template-path ./templates --snippets-path ./snippetz --values values.yaml\n\n// after\nkops toolbox template --template-path ./templates --snippets-path ./snippets --values values.yaml","handlingStrategy":"validation","validationCode":"for _, p := range snippetPaths {\n    expanded := utils.ExpandPath(p)\n    matches, err := filepath.Glob(expanded)\n    if err != nil || len(matches) == 0 {\n        return fmt.Errorf(\"snippet path %q matches no files\", p)\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Verify snippet directories exist in every environment where the command runs","Use absolute paths in scripts to avoid cwd drift","Only pass --snippets-path when snippets are actually present and needed"],"tags":["kops","snippets","templates","filesystem","cli"],"backgroundTag":"template-path-not-found","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}