{"record":{"id":"9c89a53204d722c7","repo":"kubernetes/kops","slug":"unable-to-read-snippet-s-error-s","errorCode":null,"errorMessage":"unable to read snippet: %s, error: %s","messagePattern":"unable to read snippet: (.+?), error: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kops/toolbox_template.go","lineNumber":162,"sourceCode":"\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)\n\tvar documents []string\n\tfor _, x := range templates {\n\t\tcontent, err := os.ReadFile(x)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"unable to read template: %s, error: %s\", x, err)\n\t\t}","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops/toolbox_template.go#L144-L180","documentation":"Returned by RunToolBoxTemplate when os.ReadFile fails on a snippet file that expandFiles successfully discovered. The glob expanded to a file list, but reading one of the individual files failed — typically a race (file deleted between listing and read), a permission error on the file itself, or a broken symlink.","triggerScenarios":"A snippet file listed by expandFiles is unreadable: permissions deny read for the kops user, the file was removed between glob expansion and ReadFile (CI cleanup, tmp dir), the entry is a dangling symlink, or it's a directory-ish entry without read access.","commonSituations":"Snippet files with restrictive modes (e.g. 0600 owned by another user) inside a shared snippets dir; snippets on a network mount that dropped out; CI pipelines cleaning up generated snippets mid-run; symlinked snippet dirs pointing to a removed location.","solutions":["Check permissions on the specific file named in the error (ls -l) and grant read access (chmod/chown)","Verify the file exists and is a regular file, not a broken symlink: ls -lL <file>","Re-run after ensuring no concurrent process deletes files in the snippets directory","If files are on a network/EFS mount, verify the mount is healthy and remount if needed"],"exampleFix":"// before\n-rw------- snippet.yaml  (owned by another user)\n\n// after\nchmod a+r ./snippets/snippet.yaml\nkops toolbox template --template-path ./templates --snippets-path ./snippets --values values.yaml","handlingStrategy":"try-catch","validationCode":"matches, _ := filepath.Glob(snippetDir)\nfor _, f := range matches {\n    if fi, err := os.Stat(f); err != nil || fi.IsDir() || fi.Mode().Perm()&0o400 == 0 {\n        return fmt.Errorf(\"snippet %s unreadable\", f)\n    }\n}","typeGuard":null,"tryCatchPattern":"if _, err := os.ReadFile(snippetFile); err != nil {\n    if errors.Is(err, os.ErrPermission) {\n        return fmt.Errorf(\"fix permissions on %s: %w\", snippetFile, err)\n    }\n    if errors.Is(err, os.ErrNotExist) {\n        return fmt.Errorf(\"snippet %s disappeared or is a broken symlink\", snippetFile)\n    }\n    return err\n}","preventionTips":["Keep snippet files world-readable (0644) in shared directories","Avoid concurrent cleanup jobs touching the snippets directory during renders","Replace dangling symlinks with real files or fix their targets"],"tags":["kops","snippets","filesystem","permissions"],"backgroundTag":"file-read-permission-denied","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}