nikivdev/code · error

invalid workspace path

Error message

invalid workspace path

What it means

run_workspace_add converts the workspace Path to a &str to pass to jj's workspace add command. If the path is not valid UTF-8, Path::to_str returns None and this error is thrown. It's a path-encoding precondition check, not a jj failure.

Source

Thrown at src/jj.rs:667

                branch, remote
            );
            Ok(())
        }
    }
}

fn run_workspace_add(
    repo_root: &Path,
    name: &str,
    workspace_path: PathBuf,
    rev: Option<&str>,
) -> Result<()> {
    if let Some(parent) = workspace_path.parent() {
        std::fs::create_dir_all(parent)?;
    }
    let path_str = workspace_path
        .to_str()
        .ok_or_else(|| anyhow::anyhow!("invalid workspace path"))?
        .to_string();
    let args = workspace_add_args(&path_str, name, rev);
    jj_run_owned_in(repo_root, &args)?;
    if let Some(rev) = rev.filter(|v| !v.trim().is_empty()) {
        println!(
            "Created workspace {} at {} (base: {})",
            name,
            workspace_path.display(),
            rev.trim()
        );
    } else {
        println!("Created workspace {} at {}", name, workspace_path.display());
    }
    Ok(())
}

fn workspace_add_args(destination: &str, name: &str, rev: Option<&str>) -> Vec<String> {
    let mut args = vec![

View on GitHub (pinned to a747e741ae)

Solutions

  1. Use a valid UTF-8 workspace path
  2. Check where the path comes from (args/env) and sanitize or reject non-UTF8 early
  3. If a path must be arbitrary, this API cannot support it — rename the directory

Example fix

// before
let path = std::path::PathBuf::from(bytes); // non-UTF8
// after
let path_str = std::str::from_utf8(&bytes)?; // validate UTF-8 before passing
Defensive patterns

Strategy: validation

Validate before calling

fn ensure_utf8_path(p: &std::path::Path) -> Result<(), String> {
    p.to_str().map(|_| ()).ok_or_else(|| format!("non-UTF8 path: {}", p.display()))
}

Type guard

fn is_utf8_path(p: &std::path::Path) -> bool { p.to_str().is_some() }

Prevention

When it happens

Trigger: Calling run_workspace with a workspace_path containing invalid UTF-8 bytes (e.g. non-UTF8 filenames from the filesystem or shell).

Common situations: Workspace paths derived from user input or filesystem entries with non-UTF8 encodings; environments where locale/file names use legacy encodings.

Related errors


AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01). Data as JSON: /api/errors/957afb618b044f74. Report an issue: GitHub.