{"record":{"id":"59f2b1082eb65918","repo":"charmbracelet/crush","slug":"failed-to-check-init-flag-file-w","errorCode":null,"errorMessage":"failed to check init flag file: %w","messagePattern":"failed to check init flag file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/config/init.go","lineNumber":43,"sourceCode":"\t}\n\treturn store, nil\n}\n\nfunc ProjectNeedsInitialization(store *ConfigStore) (bool, error) {\n\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}","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/config/init.go#L25-L61","documentation":"Returned by ProjectNeedsInitialization when os.Stat on the init flag file fails with an error other than NotExist (e.g. permission denied, path is invalid, or an I/O error). The function only tolerates 'file missing' or 'file exists'; any other stat failure is wrapped here.","triggerScenarios":"Calling ProjectNeedsInitialization when the init flag file path inside cfg.Options.DataDirectory is unreadable: permission errors, DataDirectory pointing somewhere invalid, or filesystem I/O errors (e.g. broken mount).","commonSituations":"Data directory on a read-only or unmounted volume; restrictive file permissions after running as different users; DataDirectory misconfigured in crushrc options.","solutions":["Check permissions on the data directory and the flag file path (ls -la).","Verify cfg.Options.DataDirectory points to a valid, accessible directory.","Fix the mount/volume state if the data directory is on an unmounted or read-only filesystem.","Ensure the process user owns or can access the data directory."],"exampleFix":"// before\nif err := os.Chmod(dataDir, 0o000); err != nil { ... }\n// after: keep data dir writable by the running user\nif err := os.Chmod(dataDir, 0o755); err != nil {\n\treturn fmt.Errorf(\"fix data dir permissions: %w\", err)\n}","handlingStrategy":"validation","validationCode":"fi, err := os.Stat(dataDir)\nif err != nil || !fi.IsDir() {\n\treturn fmt.Errorf(\"data dir invalid: %w\", err)\n}\nif err := syscall.Access(dataDir, unix.W_OK); err != nil {\n\treturn fmt.Errorf(\"data dir not writable: %w\", err)\n}","typeGuard":"func isPermOrIOError(err error) bool {\n\treturn err != nil && !os.IsNotExist(err)\n}","tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"failed to check init flag file\") {\n\t// verify data dir permissions/mount, then retry\n}","preventionTips":["Keep the data directory owned by the running user with 0o755.","Verify the volume holding the data dir is mounted and writable at startup.","Do not point DataDirectory at removable or network paths.","Avoid running some commands under sudo and others as the normal user."],"tags":["filesystem","permissions","config"],"backgroundTag":"file-stat-failed","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}