{"record":{"id":"2c4a1f8f03e24765","repo":"BoundaryML/baml","slug":"already-exists-refusing-to-overwrite-an-existing-project","errorCode":null,"errorMessage":"`{}` already exists. Refusing to overwrite an existing project.","messagePattern":"`(.+?)` already exists\\. Refusing to overwrite an existing project\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"baml_language/crates/baml_cli/src/init_command.rs","lineNumber":61,"sourceCode":"    pub name: Option<String>,\n}\n\nimpl InitArgs {\n    pub fn run(&self) -> Result<crate::ExitCode> {\n        let reporter = Reporter::new();\n        self.run_with_reporter(&reporter)\n    }\n\n    fn run_with_reporter(&self, reporter: &Reporter) -> Result<crate::ExitCode> {\n        // `init` is in-place: create-or-reuse the directory, then\n        // refuse if `baml.toml` already exists so we never clobber a\n        // project the user already initialized.\n        std::fs::create_dir_all(&self.path)\n            .with_context(|| format!(\"failed to create directory {}\", self.path.display()))?;\n        let canonical = std::fs::canonicalize(&self.path)\n            .with_context(|| format!(\"failed to canonicalize path {}\", self.path.display()))?;\n        if canonical.join(\"baml.toml\").exists() {\n            anyhow::bail!(\n                \"`{}` already exists. Refusing to overwrite an existing project.\",\n                canonical.join(\"baml.toml\").display()\n            );\n        }\n        scaffold(&canonical, self.name.as_deref(), reporter, \"Initialized\")\n    }\n}\n\n/// Create a fresh directory at `<PATH>` and\n/// scaffold a project inside. Refuses to run if `<PATH>` already exists,\n/// the same way `cargo new` does.\n///\n/// Creates the destination directory, `baml.toml`, and\n/// `baml_src/main.baml`. Use `baml init` when the directory already exists.\n#[derive(Args, Clone, Debug)]\n#[command(after_long_help = \"\\\nExamples:\n  Create a project directory:","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/baml_cli/src/init_command.rs#L43-L79","documentation":"`baml init` refuses to overwrite an already-initialized project. After creating/canonicalizing the target directory, run_with_reporter checks whether baml.toml exists inside it; if so it bails rather than clobbering existing BAML configuration. This is a safety guard protecting user scaffolding.","triggerScenarios":"Run `baml init` targeting a directory that already contains a baml.toml file (canonical path checked).","commonSituations":"Re-running `baml init` in the current project (`baml init .`), or initializing into a path you forgot was already scaffolded.","solutions":["Do nothing — the project is already initialized; run your BAML commands directly.","If you truly want a fresh project, move/delete the existing baml.toml (or the directory) and re-run `baml init`.","Initialize into a different, non-existent path with `baml init <new-path>`."],"exampleFix":"// before\nbaml init .   // bails: ./baml.toml exists\n// after\nbaml init ./my-new-project","handlingStrategy":"validation","validationCode":"# guard before `baml init <path>`\nif [ -f \"<path>/baml.toml\" ]; then echo \"already initialized\"; else baml init <path>; fi","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check for baml.toml before initializing","Treat 'already initialized' as success in scripts (idempotent init)","Don't re-run init in existing projects"],"tags":["cli","scaffold","overwrite-guard","already-exists"],"backgroundTag":"file-already-exists","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}