zed-industries/zed · error · anyhow::Error

Failed to create junction from

Error message

Failed to create junction from {:?} to {:?}

What it means

On Windows, creating a directory symlink/junction via 'cmd /C mklink /J' from {path} to {target} failed — the child process reported non-success status. mklink requires elevated privileges on some configurations and fails if the target is invalid or the junction path already exists, so create_symlink cannot complete for directory targets on this platform.

Solutions

  1. Check that the junction path does not already exist and the target directory is valid
  2. Capture mklink's stderr for the real reason (privilege/PATH issues) and surface it
  3. Retry after removing a stale junction, or fall back to copying the directory if junctions are unavailable
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at crates/fs/src/fs.rs:707 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of zed-industries/zed@916fc2b8cb (2026-08-20). Data as JSON: /api/errors/ad347b81378ee600. Report an issue: GitHub.

Appendix: source

Thrown at crates/fs/src/fs.rs:754

impl Fs for RealFs {
    async fn create_dir(&self, path: &Path) -> Result<()> {
        Ok(smol::fs::create_dir_all(path).await?)
    }

    async fn create_symlink(&self, path: &Path, target: PathBuf) -> Result<()> {
        #[cfg(unix)]
        smol::fs::unix::symlink(target, path).await?;

        #[cfg(windows)]
        if smol::fs::metadata(&target).await?.is_dir() {
            let status = new_command("cmd")
                .args(["/C", "mklink", "/J"])
                .args([path, target.as_path()])
                .status()
                .await?;

            if !status.success() {
                return Err(anyhow::anyhow!(
                    "Failed to create junction from {:?} to {:?}",
                    path,
                    target
                ));
            }
        } else {
            smol::fs::windows::symlink_file(target, path).await?
        }

        Ok(())
    }

    async fn create_file(&self, path: &Path, options: CreateOptions) -> Result<()> {
        let mut open_options = smol::fs::OpenOptions::new();
        open_options.write(true).create(true);
        if options.overwrite {
            open_options.truncate(true);
        } else if !options.ignore_if_exists {

View on GitHub (pinned to 916fc2b8cb)