{"record":{"id":"c2cae26bcf68717a","repo":"charmbracelet/crush","slug":"failed-to-check-for-context-files-w","errorCode":null,"errorMessage":"failed to check for context files: %w","messagePattern":"failed to check for context files: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/config/init.go","lineNumber":48,"sourceCode":"\tif store == nil {\n\t\treturn false, fmt.Errorf(\"config not loaded\")\n\t}\n\n\tcfg := store.Config()\n\tflagFilePath := filepath.Join(cfg.Options.DataDirectory, InitFlagFilename)\n\n\t_, err := os.Stat(flagFilePath)\n\tif err == nil {\n\t\treturn false, nil\n\t}\n\n\tif !os.IsNotExist(err) {\n\t\treturn false, fmt.Errorf(\"failed to check init flag file: %w\", err)\n\t}\n\n\tsomeContextFileExists, err := contextPathsExist(store.WorkingDir())\n\tif err != nil {\n\t\treturn false, fmt.Errorf(\"failed to check for context files: %w\", err)\n\t}\n\tif someContextFileExists {\n\t\treturn false, nil\n\t}\n\n\t// If the working directory has no non-ignored files, skip initialization step\n\tempty, err := dirHasNoVisibleFiles(store.WorkingDir())\n\tif err != nil {\n\t\treturn false, fmt.Errorf(\"failed to check if directory is empty: %w\", err)\n\t}\n\tif empty {\n\t\treturn false, nil\n\t}\n\n\treturn true, nil\n}\n\nfunc contextPathsExist(dir string) (bool, error) {","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/config/init.go#L30-L66","documentation":"Returned by ProjectNeedsInitialization when contextPathsExist fails while checking whether any context file (AGENTS.md, CRUSH.md, CLAUDE.md, GEMINI.md, etc.) exists in the working directory. Wrapped from an underlying filesystem error.","triggerScenarios":"Calling ProjectNeedsInitialization in a working directory where the context-file existence check hits a filesystem error — permission denied on the directory, the directory was deleted mid-run, or an I/O failure while globbing/statting candidate paths.","commonSituations":"Running in a directory the process cannot read; working directory removed while the app runs; NFS/remote filesystem hiccups; over-restrictive umask or sandboxing blocking directory reads.","solutions":["Verify the process has read (and traverse) permission on store.WorkingDir().","Confirm the working directory still exists and is accessible.","Check sandbox/SELinux/AppArmor policies that may block directory traversal.","Retry if the failure is a transient remote-filesystem error."],"exampleFix":"// before\nos.Chdir(deletedDir)\nneedsInit, err := config.ProjectNeedsInitialization(store)\n// after\nif _, err := os.Stat(workDir); err != nil {\n\treturn fmt.Errorf(\"working dir unavailable: %w\", err)\n}\nneedsInit, err := config.ProjectNeedsInitialization(store)","handlingStrategy":"validation","validationCode":"if fi, err := os.Stat(workDir); err != nil || !fi.IsDir() {\n\treturn fmt.Errorf(\"working dir unreadable: %w\", err)\n}","typeGuard":"func isAccessError(err error) bool {\n\treturn errors.Is(err, fs.ErrPermission) || errors.Is(err, fs.ErrNotExist)\n}","tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"failed to check for context files\") {\n\t// check dir permissions / sandbox, then retry\n}","preventionTips":["Run the tool from a directory the current user can read and traverse.","Check sandbox/SELinux policies that block directory traversal.","Verify the working directory is not deleted or remounted mid-session."],"tags":["filesystem","permissions","context-files"],"backgroundTag":"filesystem-permission-denied","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}