Hmbown/CodeWhale · error

project workspace path cannot be empty

Error message

project workspace path cannot be empty

What it means

normalize_project_workspace validates the project workspace directory path the same way the config path is validated. An empty path cannot name a workspace directory, so it is rejected up front. The workspace is where project state is rooted, so a silent default would hide a real misconfiguration.

Solutions

  1. Pass the absolute path of the project workspace directory
  2. Fix the env var / CLI flag / config key that is empty
  3. Let the tool auto-detect the workspace instead of supplying an empty value

Example fix

// before
set_workspace(PathBuf::from(""))
// after
set_workspace(PathBuf::from("/home/user/projects/myapp"))
Defensive patterns

Strategy: validation

Validate before calling

fn usable_workspace(p: &std::path::Path) -> bool {
    !p.as_os_str().is_empty()
}

Type guard

fn non_empty_workspace(p: Option<&str>) -> Option<std::path::PathBuf> {
    p.filter(|s| !s.trim().is_empty()).map(std::path::PathBuf::from)
}

Try / catch

match normalize_project_workspace(&workspace) {
    Ok(p) => p,
    Err(e) if e.to_string().contains("workspace path cannot be empty") => {
        eprintln!("workspace not set; run from the project root or pass --workspace");
        std::process::exit(2);
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: Calling the workspace-setting/config API with an empty PathBuf, an env var holding "", or a workspace argument derived from an unset CLI flag.

Common situations: Running from a context where the workspace was expected to be auto-detected but was left empty, CI jobs missing the workspace input, or config files with an empty workspace value.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


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

Appendix: source

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

        .parent()
        .context("config path must include a parent directory")?;
    let parent = match parent.canonicalize() {
        Ok(parent) => parent,
        Err(err) if err.kind() == std::io::ErrorKind::NotFound => parent.to_path_buf(),
        Err(err) => {
            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))

View on GitHub (pinned to 73e0f67d83)