{"record":{"id":"d7edb8c074d1cb46","repo":"charmbracelet/crush","slug":"failed-to-check-if-directory-is-empty-w","errorCode":null,"errorMessage":"failed to check if directory is empty: %w","messagePattern":"failed to check if directory is empty: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/config/init.go","lineNumber":57,"sourceCode":"\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) {\n\tentries, err := os.ReadDir(dir)\n\tif err != nil {\n\t\treturn false, err\n\t}\n\n\t// Create a slice of lowercase filenames for lookup with slices.Contains\n\tvar files []string\n\tfor _, entry := range entries {\n\t\tif !entry.IsDir() {","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/config/init.go#L39-L75","documentation":"Returned by ProjectNeedsInitialization when dirHasNoVisibleFiles fails while determining whether the working directory contains no non-ignored files. Used to skip initialization for empty directories; the wrap exposes the underlying filesystem error.","triggerScenarios":"Calling ProjectNeedsInitialization when the flag file is absent and no context file exists, and then the directory-emptiness scan fails due to unreadable directory entries, permission errors, or I/O failures on the working directory.","commonSituations":"Restricted read permissions on a fresh clone; directory on a failing disk or network mount; sandboxed environments denying readdir.","solutions":["Grant the process read access to the working directory.","Check filesystem health or remount if the directory is on a network/virtual mount.","Verify no security sandbox is blocking directory listing.","Ensure the working directory passed to the config store is correct."],"exampleFix":"// before\nneedsInit, err := config.ProjectNeedsInitialization(store) // fails in sandbox\n// after: run with readable workdir\nif err := os.Chmod(workDir, 0o755); err != nil {\n\treturn err\n}\nneedsInit, err = config.ProjectNeedsInitialization(store)","handlingStrategy":"validation","validationCode":"d, err := os.Open(workDir)\nif err != nil {\n\treturn fmt.Errorf(\"cannot list working dir: %w\", err)\n}\nd.Close()","typeGuard":"func isReaddirError(err error) bool {\n\treturn errors.Is(err, fs.ErrPermission) || errors.Is(err, syscall.EIO)\n}","tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"failed to check if directory is empty\") {\n\t// grant read access or fix mount, then retry init\n}","preventionTips":["Ensure the working directory grants read permission (r-x) to the running user.","Avoid network mounts with unreliable readdir behavior for project dirs.","Test the app in your sandbox/CI environment before deployment."],"tags":["filesystem","directory","permissions"],"backgroundTag":"filesystem-permission-denied","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}