{"record":{"id":"da079cb29f8a330f","repo":"neondatabase/neon","slug":"directory-not-empty-base-path","errorCode":null,"errorMessage":"directory not empty: {base_path:?}","messagePattern":"directory not empty: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"control_plane/src/local_env.rs","lineNumber":882,"sourceCode":"    /// Materialize the [`NeonLocalInitConf`] to disk. Called during [`neon_local init`].\n    pub fn init(conf: NeonLocalInitConf, force: &InitForceMode) -> anyhow::Result<()> {\n        let base_path = base_path();\n        assert_ne!(base_path, Path::new(\"\"));\n        let base_path = &base_path;\n\n        // create base_path dir\n        if base_path.exists() {\n            match force {\n                InitForceMode::MustNotExist => {\n                    bail!(\n                        \"directory '{}' already exists. Perhaps already initialized?\",\n                        base_path.display()\n                    );\n                }\n                InitForceMode::EmptyDirOk => {\n                    if let Some(res) = std::fs::read_dir(base_path)?.next() {\n                        res.context(\"check if directory is empty\")?;\n                        anyhow::bail!(\"directory not empty: {base_path:?}\");\n                    }\n                }\n                InitForceMode::RemoveAllContents => {\n                    println!(\"removing all contents of '{}'\", base_path.display());\n                    // instead of directly calling `remove_dir_all`, we keep the original dir but removing\n                    // all contents inside. This helps if the developer symbol links another directory (i.e.,\n                    // S3 local SSD) to the `.neon` base directory.\n                    for entry in std::fs::read_dir(base_path)? {\n                        let entry = entry?;\n                        let path = entry.path();\n                        if path.is_dir() {\n                            fs::remove_dir_all(&path)?;\n                        } else {\n                            fs::remove_file(&path)?;\n                        }\n                    }\n                }\n            }","sourceCodeStart":864,"sourceCodeEnd":900,"githubUrl":"https://github.com/neondatabase/neon/blob/8f60b04da47ffefe0e52bda2440134b42874eb75/control_plane/src/local_env.rs#L864-L900","documentation":"neon local init with the EmptyDirOk force mode requires the target base directory (default .neon) to contain nothing at all. The code peeks at the first entry from read_dir; if any entry exists (hidden dotfiles included), init aborts rather than mixing a fresh environment with stale state.","triggerScenarios":"Running init into an existing directory holding leftover datadirs, logs, pid files, or dotfiles; re-running init after a partially failed previous attempt; a symlinked cache/SSD directory that already has content.","commonSituations":"Re-initializing a dev environment without the destructive force flag, switching env configs while keeping the same .neon path, reused CI workspaces.","solutions":["Remove the directory contents (or the whole directory) and re-run init","Use the destructive force mode (RemoveAllContents), which clears contents but keeps the dir itself — safe when .neon is a symlink to another volume","Point the env config at a fresh empty base_dir"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// before LocalEnv init with EmptyDirOk\nlet is_empty = match std::fs::read_dir(&base_path) {\n    Ok(mut it) => it.next().is_none(),\n    Err(e) if e.kind() == std::io::ErrorKind::NotFound => true,\n    Err(e) => return Err(e.into()),\n};\nanyhow::ensure!(is_empty, \"{} is not empty — clean it or use force\", base_path.display());","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Give each environment its own base_dir","Script teardown (destroy) immediately after failed inits","Remember read_dir also sees dotfiles — check with ls -la before init"],"tags":["rust","neon-local","filesystem","init","local-env"],"backgroundTag":"directory-not-empty","analyzedSha":"8f60b04da47ffefe0e52bda2440134b42874eb75","analyzedAt":"2026-08-16T23:39:28.135Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}