affaan-m/ECC · error · anyhow::Error

worktree_branch_prefix cannot be empty

Error message

worktree_branch_prefix cannot be empty

What it means

branch_name_for_session builds `{prefix}/{session_id}` and requires the configured worktree_branch_prefix to be non-empty after trimming whitespace and surrounding slashes. An empty/blank prefix makes branch derivation impossible and is treated as a config error.

Source

Thrown at ecc2/src/worktree/mod.rs:163

        );
    }

    Ok(info)
}

pub fn sync_shared_dependency_dirs(worktree: &WorktreeInfo) -> Result<Vec<String>> {
    let repo_root = base_checkout_path(worktree)?;
    sync_shared_dependency_dirs_in_repo(worktree, &repo_root)
}

pub(crate) fn branch_name_for_session(
    session_id: &str,
    cfg: &Config,
    repo_root: &Path,
) -> Result<String> {
    let prefix = cfg.worktree_branch_prefix.trim().trim_matches('/');
    if prefix.is_empty() {
        anyhow::bail!("worktree_branch_prefix cannot be empty");
    }

    let branch = format!("{prefix}/{session_id}");
    validate_branch_name(repo_root, &branch).with_context(|| {
        format!(
            "Invalid worktree branch '{branch}' derived from prefix '{}' and session id '{session_id}'",
            cfg.worktree_branch_prefix
        )
    })?;

    Ok(branch)
}

/// Remove a worktree and its branch.
pub fn remove(worktree: &WorktreeInfo) -> Result<()> {
    let repo_root = match base_checkout_path(worktree) {
        Ok(path) => path,
        Err(error) => {

View on GitHub (pinned to 01e15490f0)

Solutions

  1. Set worktree_branch_prefix to a non-empty value (e.g. "ecc2-sessions") in the config.
  2. Validate the config at load time and fail fast with a clear, named error before any session starts.
  3. Provide a sensible non-empty default in the Config constructor so an unset key can never reach this path.

Example fix

// before
let branch = branch_name_for_session(&session_id, &cfg, repo_root)?;

// after (config side)
impl Default for Config {
    fn default() -> Self {
        Self { worktree_branch_prefix: "ecc2-sessions".to_string(), .. }
    }
}
// load-time guard
let prefix = cfg.worktree_branch_prefix.trim().trim_matches('/');
if prefix.is_empty() {
    return Err(anyhow::anyhow!("config 'worktree_branch_prefix' must be set"));
}
let branch = branch_name_for_session(&session_id, &cfg, repo_root)?;
Defensive patterns

Strategy: validation

Validate before calling

fn validate_branch_prefix(cfg: &Config) -> Result<()> {
    let p = cfg.worktree_branch_prefix.trim().trim_matches('/');
    if p.is_empty() {
        return Err(anyhow::anyhow!("config 'worktree_branch_prefix' must be non-empty"));
    }
    Ok(())
}

validate_branch_prefix(&cfg)?;
let branch = branch_name_for_session(&session_id, &cfg, repo_root)?;

Type guard

fn branch_prefix_is_valid(cfg: &Config) -> bool {
    !cfg.worktree_branch_prefix.trim().trim_matches('/').is_empty()
}

Try / catch

match branch_name_for_session(&session_id, &cfg, repo_root) {
    Ok(branch) => { /* ok */ }
    Err(e) if e.to_string().contains("worktree_branch_prefix cannot be empty") => {
        // set cfg.worktree_branch_prefix to a non-empty value and retry
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: cfg.worktree_branch_prefix, after .trim().trim_matches('/'), is empty — i.e. the configured value is empty, whitespace-only, or consists solely of slashes.

Common situations: The worktree_branch_prefix config key is missing; its default is the empty string; an env-var override was set to empty; the config file was partially templated and left the key blank.

Related errors


AI-assisted analysis of affaan-m/ECC@01e15490f0 (2026-08-13). Data as JSON: /api/errors/539991d139025550. Report an issue: GitHub.