{"record":{"id":"957afb618b044f74","repo":"nikivdev/code","slug":"invalid-workspace-path-957afb","errorCode":null,"errorMessage":"invalid workspace path","messagePattern":"invalid workspace path","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/jj.rs","lineNumber":667,"sourceCode":"                branch, remote\n            );\n            Ok(())\n        }\n    }\n}\n\nfn run_workspace_add(\n    repo_root: &Path,\n    name: &str,\n    workspace_path: PathBuf,\n    rev: Option<&str>,\n) -> Result<()> {\n    if let Some(parent) = workspace_path.parent() {\n        std::fs::create_dir_all(parent)?;\n    }\n    let path_str = workspace_path\n        .to_str()\n        .ok_or_else(|| anyhow::anyhow!(\"invalid workspace path\"))?\n        .to_string();\n    let args = workspace_add_args(&path_str, name, rev);\n    jj_run_owned_in(repo_root, &args)?;\n    if let Some(rev) = rev.filter(|v| !v.trim().is_empty()) {\n        println!(\n            \"Created workspace {} at {} (base: {})\",\n            name,\n            workspace_path.display(),\n            rev.trim()\n        );\n    } else {\n        println!(\"Created workspace {} at {}\", name, workspace_path.display());\n    }\n    Ok(())\n}\n\nfn workspace_add_args(destination: &str, name: &str, rev: Option<&str>) -> Vec<String> {\n    let mut args = vec![","sourceCodeStart":649,"sourceCodeEnd":685,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/jj.rs#L649-L685","documentation":"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.","triggerScenarios":"Calling run_workspace with a workspace_path containing invalid UTF-8 bytes (e.g. non-UTF8 filenames from the filesystem or shell).","commonSituations":"Workspace paths derived from user input or filesystem entries with non-UTF8 encodings; environments where locale/file names use legacy encodings.","solutions":["Use a valid UTF-8 workspace path","Check where the path comes from (args/env) and sanitize or reject non-UTF8 early","If a path must be arbitrary, this API cannot support it — rename the directory"],"exampleFix":"// before\nlet path = std::path::PathBuf::from(bytes); // non-UTF8\n// after\nlet path_str = std::str::from_utf8(&bytes)?; // validate UTF-8 before passing","handlingStrategy":"validation","validationCode":"fn ensure_utf8_path(p: &std::path::Path) -> Result<(), String> {\n    p.to_str().map(|_| ()).ok_or_else(|| format!(\"non-UTF8 path: {}\", p.display()))\n}","typeGuard":"fn is_utf8_path(p: &std::path::Path) -> bool { p.to_str().is_some() }","tryCatchPattern":null,"preventionTips":["Validate paths are UTF-8 at CLI/argument parsing time","Avoid building paths from raw OS byte strings","Use Path::to_str().context(...) early with a clear user message"],"tags":["path","utf8","jj","workspace"],"backgroundTag":"invalid-utf8-path","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}