affaan-m/ECC · error

worktree_branch_prefix cannot be empty

Error message

worktree_branch_prefix cannot be empty

What it means

branch_name_for_session derives the worktree branch as `<prefix>/<session_id>` after trimming whitespace and trailing slashes from cfg.worktree_branch_prefix. If the prefix is empty (or only slashes/whitespace), it bails rather than producing an invalid branch like '/session-id'.

Solutions

  1. Set worktree_branch_prefix to a non-empty value (e.g. "ecc" or "session") in your config
  2. Add a startup config validation that rejects empty prefixes before any session is created
  3. Use a fallback default in code when the field is missing: prefix = if cfg_prefix.is_empty() { "ecc" } else { cfg_prefix }

Example fix

// before
worktree_branch_prefix = ""
// after
worktree_branch_prefix = "ecc"
Defensive patterns

Strategy: validation

Validate before calling

// Validate config at startup
let prefix = cfg.worktree_branch_prefix.trim().trim_matches('/');
if prefix.is_empty() {
    return Err(anyhow::anyhow!("worktree_branch_prefix must be a non-empty branch prefix, e.g. 'ecc'"));
}

Prevention

When it happens

Trigger: Constructing a Config with worktree_branch_prefix set to "", " ", "/", or "///" and calling create_for_session.

Common situations: A config file where the prefix key is present but blank; environment-driven config where the prefix variable was unset and defaulted to empty; a YAML/TOML value of "" instead of a sensible default like "ecc".

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


AI-assisted analysis of affaan-m/ECC@8321021c54 (2026-09-16). Data as JSON: /api/errors/539991d139025550. Report an issue: GitHub.

Appendix: 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 8321021c54)