BoundaryML/baml · error

` ` already exists. Refusing to overwrite an existing…

Error message

`{}` already exists. Refusing to overwrite an existing project.

What it means

`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.

Solutions

  1. Do nothing — the project is already initialized; run your BAML commands directly.
  2. If you truly want a fresh project, move/delete the existing baml.toml (or the directory) and re-run `baml init`.
  3. Initialize into a different, non-existent path with `baml init <new-path>`.

Example fix

// before
baml init .   // bails: ./baml.toml exists
// after
baml init ./my-new-project
Defensive patterns

Strategy: validation

Validate before calling

# guard before `baml init <path>`
if [ -f "<path>/baml.toml" ]; then echo "already initialized"; else baml init <path>; fi

Prevention

When it happens

Trigger: Run `baml init` targeting a directory that already contains a baml.toml file (canonical path checked).

Common situations: Re-running `baml init` in the current project (`baml init .`), or initializing into a path you forgot was already scaffolded.

Understand the failure class

Background: "already exists" / EEXIST / FileAlreadyExistsException: what the 'file already exists' error means and how to fix it — this error's family across 37 libraries.

Related errors


AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12). Data as JSON: /api/errors/2c4a1f8f03e24765. Report an issue: GitHub.

Appendix: source

Thrown at baml_language/crates/baml_cli/src/init_command.rs:61

    pub name: Option<String>,
}

impl InitArgs {
    pub fn run(&self) -> Result<crate::ExitCode> {
        let reporter = Reporter::new();
        self.run_with_reporter(&reporter)
    }

    fn run_with_reporter(&self, reporter: &Reporter) -> Result<crate::ExitCode> {
        // `init` is in-place: create-or-reuse the directory, then
        // refuse if `baml.toml` already exists so we never clobber a
        // project the user already initialized.
        std::fs::create_dir_all(&self.path)
            .with_context(|| format!("failed to create directory {}", self.path.display()))?;
        let canonical = std::fs::canonicalize(&self.path)
            .with_context(|| format!("failed to canonicalize path {}", self.path.display()))?;
        if canonical.join("baml.toml").exists() {
            anyhow::bail!(
                "`{}` already exists. Refusing to overwrite an existing project.",
                canonical.join("baml.toml").display()
            );
        }
        scaffold(&canonical, self.name.as_deref(), reporter, "Initialized")
    }
}

/// Create a fresh directory at `<PATH>` and
/// scaffold a project inside. Refuses to run if `<PATH>` already exists,
/// the same way `cargo new` does.
///
/// Creates the destination directory, `baml.toml`, and
/// `baml_src/main.baml`. Use `baml init` when the directory already exists.
#[derive(Args, Clone, Debug)]
#[command(after_long_help = "\
Examples:
  Create a project directory:

View on GitHub (pinned to bd85ce9dee)