nikivdev/code · error
invalid workspace path
Error message
invalid workspace path
What it means
In `prepare_source_workspace` (called from `import_external_path`), the CLI converts the computed workspace path to a string with `Path::to_str()` before passing it as an argument to the internal `workspace add` command. `to_str()` returns `None` for non-UTF-8 paths, and the code surfaces this as 'invalid workspace path'.
Source
Thrown at src/ext.rs:286
}
}
let workspaces = jj_workspace_list(&repo_root).unwrap_or_default();
if let Some(existing_path) = workspaces.get(&workspace) {
return Ok(PathBuf::from(existing_path));
}
let base = workspace_base(&repo_root)?;
fs::create_dir_all(&base).with_context(|| format!("failed to create {}", base.display()))?;
let workspace_path = base.join(&workspace);
jj_run_in(
&repo_root,
&[
"workspace",
"add",
workspace_path
.to_str()
.ok_or_else(|| anyhow::anyhow!("invalid workspace path"))?,
"--name",
&workspace,
],
)?;
println!(
"Created jj workspace {} at {}",
workspace,
workspace_path.display()
);
Ok(workspace_path)
}
fn workspace_name_for_project(project_root: &Path) -> Result<String> {
let home = std::env::var("HOME").ok();
let mut relative = None;
if let Some(home) = home.as_deref() {
if let Ok(stripped) = project_root.strip_prefix(home) {View on GitHub (pinned to a747e741ae)
Solutions
- Rename the offending directories/files to valid UTF-8 names before importing
- Re-clone or re-copy the external repository into a path with standard UTF-8 names
- Import from a parent directory whose path to the repo root is plain ASCII/UTF-8
Example fix
// before mv 'repos/caf$\xe9' repos/cafe f ext import repos/cafe // after f ext import repos/cafe # succeeds: path is valid UTF-8
Defensive patterns
Strategy: validation
Validate before calling
fn ensure_utf8_path(p: &std::path::Path) -> anyhow::Result<&str> {
p.to_str().ok_or_else(|| anyhow::anyhow!("path is not valid UTF-8: {}", p.display()))
} Type guard
fn is_valid_utf8_path(p: &std::path::Path) -> bool { p.to_str().is_some() } Prevention
- Keep repo and workspace paths UTF-8 clean
- Re-clone sources with non-UTF-8 filenames before importing
- Avoid importing paths assembled from raw OS bytes
When it happens
Trigger: Importing an external path whose resolved repository/workspace path contains invalid UTF-8 bytes (e.g. from a filesystem allowing arbitrary byte sequences in names), so `workspace_path.to_str()` is `None`.
Common situations: Repositories or checkouts with non-UTF-8 file/directory names (common with legacy encodings or files created on other OSes); paths built from raw bytes on Linux; NFS/external drives with unusual naming.
Related errors
- Path not found: {}
- target path exists but is not a git checkout: {}
- Postgres project path not found: {} (override with --project
- invalid policy path {}
- handled before project context load
AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01).
Data as JSON: /api/errors/f7d2ffc082a39f1b.
Report an issue: GitHub.