{"record":{"id":"eefa1b74be38d1e5","repo":"charmbracelet/crush","slug":"failed-to-create-init-flag-file-w","errorCode":null,"errorMessage":"failed to create init flag file: %w","messagePattern":"failed to create init flag file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/config/init.go","lineNumber":111,"sourceCode":"\n// dirHasNoVisibleFiles returns true if the directory has no files/dirs after applying ignore rules.\nfunc dirHasNoVisibleFiles(dir string) (bool, error) {\n\tfiles, _, err := fsext.ListDirectory(dir, nil, 1, 1)\n\tif err != nil {\n\t\treturn false, err\n\t}\n\treturn len(files) == 0, nil\n}\n\nfunc MarkProjectInitialized(store *ConfigStore) error {\n\tif store == nil {\n\t\treturn fmt.Errorf(\"config not loaded\")\n\t}\n\tflagFilePath := filepath.Join(store.Config().Options.DataDirectory, InitFlagFilename)\n\n\tfile, err := os.Create(flagFilePath)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to create init flag file: %w\", err)\n\t}\n\tdefer file.Close()\n\n\treturn nil\n}\n\nfunc HasInitialDataConfig(store *ConfigStore) bool {\n\tif store == nil {\n\t\treturn false\n\t}\n\tcfgPath := GlobalConfigData()\n\tif _, err := os.Stat(cfgPath); err != nil {\n\t\treturn false\n\t}\n\treturn store.Config().IsConfigured()\n}\n","sourceCodeStart":93,"sourceCodeEnd":128,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/config/init.go#L93-L128","documentation":"Returned by MarkProjectInitialized when os.Create fails to create the init flag file inside cfg.Options.DataDirectory. The wrap exposes the underlying OS error (permission denied, missing directory, read-only filesystem, etc.).","triggerScenarios":"Calling MarkProjectInitialized when the data directory does not exist, is read-only, or the process lacks write permission for the flag file path.","commonSituations":"First-run on a system where the data directory was never created; running under a different user than the one owning the data dir; container/rootless setups with read-only home directories; disk full.","solutions":["Ensure the data directory exists (os.MkdirAll) before calling MarkProjectInitialized.","Fix write permissions on the data directory for the running user.","Check for read-only mounts or full disks and free space or remount writable.","Run under the user that owns the data directory (avoid sudo/user mismatch)."],"exampleFix":"// before\nerr := config.MarkProjectInitialized(store) // fails: dir missing\n// after\nif err := os.MkdirAll(dataDir, 0o755); err != nil {\n\treturn fmt.Errorf(\"create data dir: %w\", err)\n}\nerr := config.MarkProjectInitialized(store)","handlingStrategy":"validation","validationCode":"if err := os.MkdirAll(dataDir, 0o755); err != nil {\n\treturn fmt.Errorf(\"cannot create data dir: %w\", err)\n}","typeGuard":"func canWrite(path string) bool {\n\treturn unix.Access(path, unix.W_OK) == nil\n}","tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"failed to create init flag file\") {\n\t// check disk space, permissions, and mount state before retry\n}","preventionTips":["Create the data directory with os.MkdirAll before first use.","Keep disks from filling; monitor free space.","Run consistently as one user; avoid sudo-induced permission drift.","Mount home/data volumes read-write in containers."],"tags":["filesystem","permissions","initialization"],"backgroundTag":"file-create-permission-denied","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}