Hmbown/CodeWhale · error

workspace path cannot be empty

Error message

workspace path cannot be empty

What it means

`checked_workspace_path` rejects an empty workspace path before deriving the project MCP config location (`.codewhale/mcp.json`). An empty `Path` cannot yield a meaningful config file location, so the library fails fast with this validation error instead of writing to a nonsensical path.

Solutions

  1. Pass a valid absolute workspace path to the API (e.g. `std::env::current_dir()?` when no explicit workspace exists)
  2. Ensure the workspace is resolved and non-empty before calling MCP config functions
  3. If no project is open, avoid project-scope MCP config operations entirely

Example fix

// before
let workspace = PathBuf::from(settings.workspace.unwrap_or_default()); // "" when unset
// after
let workspace = settings.workspace.map(PathBuf::from).unwrap_or_else(|| std::env::current_dir().expect("cwd"));
Defensive patterns

Strategy: validation

Validate before calling

if workspace.as_os_str().is_empty() {
    return Err(anyhow::anyhow!("workspace path cannot be empty"));
}

Type guard

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

Try / catch

match checked_workspace_path(&workspace) {
    Ok(p) => p,
    Err(e) if e.to_string().contains("cannot be empty") => return Err(ensure_workspace_loaded()),
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: Calling any function that passes a `&Path` workspace into `checked_workspace_path` (crates/tui/src/mcp.rs:5613) with `Path::new("")` or `PathBuf::new()` — e.g. when the caller has no workspace loaded yet.

Common situations: Launching the TUI outside a project with an unset workspace variable; a caller defaulting a missing CLI flag to an empty string; a config file where the workspace field was dropped or is `""`.

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/ee344c0bcdb5a1e9. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/src/mcp.rs:5613

    if !resolved.starts_with(plugin_path) {
        anyhow::bail!("reviewed plugin MCP path escaped its staged root");
    }
    Ok(resolved)
}

fn workspace_allows_project_mcp_config(workspace: &Path) -> bool {
    crate::config::is_workspace_trusted(workspace)
}

fn checked_workspace_mcp_config_path(workspace: &Path) -> Result<PathBuf> {
    Ok(checked_workspace_path(workspace)?
        .join(".codewhale")
        .join("mcp.json"))
}

fn checked_workspace_path(workspace: &Path) -> Result<PathBuf> {
    if workspace.as_os_str().is_empty() {
        anyhow::bail!("workspace path cannot be empty");
    }
    if workspace
        .components()
        .any(|component| matches!(component, Component::ParentDir))
    {
        anyhow::bail!("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 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)