{"record":{"id":"df5476b58c0a8f7e","repo":"plandex-ai/plandex","slug":"error-checking-if-settings-v2-json-exists-v","errorCode":null,"errorMessage":"error checking if settings-v2.json exists: %v","messagePattern":"error checking if settings-v2\\.json exists: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/cli/lib/current.go","lineNumber":187,"sourceCode":"\t\t}\n\t}\n}\n\nfunc loadCurrentBranch() error {\n\t// Load plan-specific settings\n\tif CurrentPlanId == \"\" {\n\t\treturn fmt.Errorf(\"no current plan\")\n\t}\n\n\tpath := filepath.Join(HomeCurrentProjectDir, CurrentPlanId, \"settings-v2.json\")\n\n\t// Check if the file exists\n\t_, err := os.Stat(path)\n\n\tif os.IsNotExist(err) {\n\t\treturn nil\n\t} else if err != nil {\n\t\treturn fmt.Errorf(\"error checking if settings-v2.json exists: %v\", err)\n\t}\n\n\tfileBytes, err := os.ReadFile(path)\n\tif err != nil {\n\t\tterm.OutputErrorAndExit(\"error reading settings-v2.json: %v\", err)\n\t}\n\n\tvar settingsByAccount types.PlanSettingsByAccount\n\terr = json.Unmarshal(fileBytes, &settingsByAccount)\n\tif err != nil {\n\t\tterm.OutputErrorAndExit(\"error unmarshalling settings-v2.json: %v\", err)\n\t}\n\tsettings := settingsByAccount[auth.Current.UserId]\n\n\tif settings == nil {\n\t\treturn nil\n\t}\n","sourceCodeStart":169,"sourceCodeEnd":205,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/cli/lib/current.go#L169-L205","documentation":"loadCurrentBranch stats <HomeCurrentProjectDir>/<CurrentPlanId>/settings-v2.json and wraps any stat error that is NOT 'file does not exist' as 'error checking if settings-v2.json exists: %v'. It distinguishes a genuinely failed stat (permissions, path issues) from a missing file (which returns nil).","triggerScenarios":"os.Stat on the settings-v2.json path returns an error that is neither nil nor os.IsNotExist — e.g. permission denied on the plan directory, I/O error, path is not a directory, or a symlink loop.","commonSituations":"Restrictive file permissions on ~/.<app>/current-project/<planId>/; the plan directory was replaced by a file; disk/network home-directory issues (e.g. NFS/roaming profiles); antivirus locking the path on Windows.","solutions":["Check permissions on HomeCurrentProjectDir/<CurrentPlanId>/ and fix with chmod/chown","Verify the path is a directory and settings-v2.json is a regular readable file","Inspect the wrapped stat error (%v) for the exact OS reason","Recreate the plan directory/settings file if the state is corrupted"],"exampleFix":"// before\n_, err := os.Stat(path)\nif err != nil && !os.IsNotExist(err) {\n    return fmt.Errorf(\"error checking if settings-v2.json exists: %v\", err)\n}\n// after: caller-side preflight\nif info, err := os.Stat(planDir); err != nil || !info.IsDir() {\n    term.OutputErrorAndExit(\"plan dir unreadable: %v — check permissions\", planDir)\n}","handlingStrategy":"validation","validationCode":"planDir := filepath.Join(HomeCurrentProjectDir, CurrentPlanId)\nif info, err := os.Stat(planDir); err != nil || !info.IsDir() {\n    return fmt.Errorf(\"plan directory unavailable: %s (%v)\", planDir, err)\n}","typeGuard":"func settingsReadable(path string) bool {\n    info, err := os.Stat(path)\n    return err == nil || os.IsNotExist(err) // only these two are handleable\n}","tryCatchPattern":"current, err := MustLoadCurrentPlan()\nif err != nil && strings.Contains(err.Error(), \"error checking if settings-v2.json exists\") {\n    fmt.Fprintf(os.Stderr, \"check permissions on %s: %v\\n\", HomeCurrentProjectDir, err)\n    os.Exit(1)\n}","preventionTips":["Keep app state directories owned by the running user with 0755/0600 permissions","Never replace state directories with regular files","Watch for AV/sync tools locking files under the home directory"],"tags":["filesystem","permissions","settings","cli"],"backgroundTag":"file-stat-failed","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}