jdx/mise · error · eyre::Report

refusing to replace non-file path

Error message

refusing to replace non-file path {}; set replace = true to allow replacement

What it means

When a [bootstrap.files] entry targets a path occupied by something that is not a regular file (directory, symlink-to-directory, etc.) and the requested state is not Absent, operation() refuses to clobber it unless the entry explicitly sets replace = true. This is a safety guard against destroying unexpected directory trees while installing a file.

Solutions

  1. Set `replace = true` on the file entry to authorize replacing the non-file path.
  2. Remove or relocate the existing non-file path manually or via a [bootstrap.directories] absent entry.
  3. Adjust the declared path if it unintentionally collides with a directory.

Example fix

# before
[bootstrap.files]
"/etc/app" = { content = "...", state = "present" }

# after
[bootstrap.files]
"/etc/app" = { content = "...", state = "present", replace = true }
Defensive patterns

Strategy: validation

Validate before calling

// preflight: require explicit replace=true when target exists as non-file
fn preflight_present_file(path: &Path, replace: bool) -> Result<(), String> {
    match std::fs::symlink_metadata(path) {
        Ok(md) if !md.is_file() && !replace => {
            Err(format!("{} exists and is not a file; set replace = true", path.display()))
        }
        _ => Ok(()),
    }
}

Try / catch

// catch the refusal and surface the remediation flag
match result {
    Err(e) if e.contains("set replace = true") => {
        eprintln!("add `replace = true` to the entry or clear the path: {}", e);
    }
    other => other?,
}

Prevention

When it happens

Trigger: Executing a managed file action where plan() yields ResourceAction::Unknown for a non-file existing path and the entry's state is Present (replace not enabled).

Common situations: Installing a config where a package or previous setup created a directory at the same path; switching a managed path from directory to file semantics without opting in; mount points or sockets sitting at the declared path.

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 jdx/mise@533346cc37 (2026-09-17). Data as JSON: /api/errors/6991963a7e0213ba. Report an issue: GitHub.

Appendix: source

Thrown at src/system/managed_files.rs:664

            inspection: None,
        })
    }

    pub(crate) fn plan(&self) -> Result<ResourcePlan> {
        plan_file(self).map(|plan| {
            plan.with_origin(self.origin.clone())
                .with_file_phase(self.phase)
        })
    }

    fn operation(&self) -> Result<Option<PrivilegedAction>> {
        match self.plan()?.action {
            ResourceAction::Noop => return Ok(None),
            ResourceAction::Unknown if self.state == ManagedState::Absent => bail!(
                "refusing to remove directory {} as a file; declare it in [bootstrap.directories]",
                self.path.display()
            ),
            ResourceAction::Unknown => bail!(
                "refusing to replace non-file path {}; set replace = true to allow replacement",
                self.path.display()
            ),
            _ => {}
        }
        Ok(Some(match self.state {
            ManagedState::Present => PrivilegedAction::WriteFile {
                path: self.path.clone(),
                content: self.content.clone().expect("present file has content"),
                owner: self.owner.clone(),
                group: self.group.clone(),
                mode: self.mode,
                replace: self.replace,
            },
            ManagedState::Absent => PrivilegedAction::RemoveFile {
                path: self.path.clone(),
            },
        }))

View on GitHub (pinned to 533346cc37)