linera-io/linera-protocol · error · anyhow::Error

Directory {} already exists

Error message

Directory {} already exists

What it means

When create_new derives the target directory from the project name (no explicit dir given), it refuses to overwrite an existing directory, so scaffolding fails if ./<name> already exists on disk.

Source

Thrown at linera-service/src/project.rs:37

    root: PathBuf,
}

impl Project {
    /// Creates a new application project from the template, scaffolding its files.
    pub fn create_new(
        name: &str,
        linera_root: Option<&Path>,
        dir: Option<PathBuf>,
    ) -> Result<Self> {
        ensure!(
            !name.contains(std::path::is_separator),
            "Project name {name} should not contain path-separators",
        );
        let root = match dir {
            Some(dir) => dir,
            None => {
                let root = PathBuf::from(name);
                ensure!(
                    !root.exists(),
                    "Directory {} already exists",
                    root.display(),
                );
                root
            }
        };
        ensure!(
            root.extension().is_none(),
            "Project name {name} should not have a file extension",
        );
        debug!("Creating directory at {}", root.display());
        fs_err::create_dir_all(&root)?;

        debug!("Creating the source directory");
        let source_directory = Self::create_source_directory(&root)?;

        debug!("Creating the tests directory");

View on GitHub (pinned to 6c226ddcb3)

Solutions

  1. Remove or rename the existing directory, then re-run the command
  2. Choose a different project name
  3. If supported by your flow, scaffold into an explicit empty directory instead

Example fix

# before
$ ls
my-dapp/
$ linera project new my-dapp
error: Directory my-dapp already exists

# after
$ mv my-dapp my-dapp-old
$ linera project new my-dapp
Defensive patterns

Strategy: validation

Validate before calling

let root = std::path::PathBuf::from(name);
if root.exists() {
    anyhow::bail!("directory {} already exists; remove it or pick another name", root.display());
}

Prevention

When it happens

Trigger: Running `linera project new <name>` when a directory with that name already exists in the current working directory — e.g. running the scaffold twice.

Common situations: Retrying a failed scaffold without cleaning up; name collisions with pre-existing folders.

Related errors


AI-assisted analysis of linera-io/linera-protocol@6c226ddcb3 (2026-08-22). Data as JSON: /api/errors/1448af868049b017. Report an issue: GitHub.