Hmbown/CodeWhale · error

project workspace path cannot contain '..' components

Error message

project workspace path cannot contain '..' components

What it means

normalize_project_workspace rejects workspace paths containing '..' components, mirroring the config-path rule. This blocks traversal outside the intended project root and forces unambiguous path input. Resolve the path yourself if you genuinely need parent-directory semantics.

Solutions

  1. Use an absolute workspace path without '..' components
  2. Canonicalize the path with std::fs::canonicalize (or realpath) before passing it
  3. Rewrite the relative path so it contains no parent components

Example fix

// before
set_workspace(PathBuf::from("/srv/../home/u/proj"))
// after
set_workspace(PathBuf::from("/home/u/proj"))
Defensive patterns

Strategy: validation

Validate before calling

fn no_parent_components(p: &std::path::Path) -> bool {
    use std::path::Component;
    !p.components().any(|c| matches!(c, Component::ParentDir))
}

Type guard

fn safe_workspace(p: &str) -> Option<std::path::PathBuf> {
    use std::path::Component;
    let path = std::path::PathBuf::from(p);
    (!path.components().any(|c| matches!(c, Component::ParentDir))).then_some(path)
}

Try / catch

match normalize_project_workspace(&workspace) {
    Ok(p) => p,
    Err(e) if e.to_string().contains("'..' components") => {
        let real = std::fs::canonicalize(&workspace).ok()?;
        normalize_project_workspace(&real)?
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: Passing a workspace path like "~/project/../other" (even though ~ was expanded), "/srv/../home/u/proj", or "sub/../." to the workspace setting API.

Common situations: Shell scripts constructing workspaces from variables with ../ segments, users writing relative workspaces in config.toml, or tools templating monorepo paths with parent jumps.

Understand the failure class

Background: Path traversal blocked: "path escapes the workspace" and "outside site root" errors when a path will not stay inside its allowed directory — this error's family across 26 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/d216f31a1d13e1c9. Report an issue: GitHub.

Appendix: source

Thrown at crates/config/src/lib.rs:6804

            return Err(err).with_context(|| {
                format!("failed to resolve config directory {}", parent.display())
            });
        }
    };
    let normalized = parent.join(file_name);
    reject_path_symlink(&normalized)?;
    Ok(normalized)
}

fn normalize_project_workspace(workspace: &Path) -> Result<PathBuf> {
    if workspace.as_os_str().is_empty() {
        bail!("project workspace path cannot be empty");
    }
    if workspace
        .components()
        .any(|component| matches!(component, Component::ParentDir))
    {
        bail!("project workspace path cannot contain '..' components");
    }
    let absolute = if workspace.is_absolute() {
        workspace.to_path_buf()
    } else {
        std::env::current_dir()
            .context("failed to resolve current directory for project workspace")?
            .join(workspace)
    };
    match absolute.canonicalize() {
        Ok(path) => Ok(path),
        Err(err) if err.kind() == std::io::ErrorKind::NotFound => {
            Ok(normalize_path_components(&absolute))
        }
        Err(err) => Err(err).with_context(|| {
            format!(
                "failed to resolve project workspace {}",
                workspace.display()
            )

View on GitHub (pinned to 73e0f67d83)