{"record":{"id":"539991d139025550","repo":"affaan-m/ECC","slug":"worktree-branch-prefix-cannot-be-empty","errorCode":null,"errorMessage":"worktree_branch_prefix cannot be empty","messagePattern":"worktree_branch_prefix cannot be empty","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"ecc2/src/worktree/mod.rs","lineNumber":163,"sourceCode":"        );\n    }\n\n    Ok(info)\n}\n\npub fn sync_shared_dependency_dirs(worktree: &WorktreeInfo) -> Result<Vec<String>> {\n    let repo_root = base_checkout_path(worktree)?;\n    sync_shared_dependency_dirs_in_repo(worktree, &repo_root)\n}\n\npub(crate) fn branch_name_for_session(\n    session_id: &str,\n    cfg: &Config,\n    repo_root: &Path,\n) -> Result<String> {\n    let prefix = cfg.worktree_branch_prefix.trim().trim_matches('/');\n    if prefix.is_empty() {\n        anyhow::bail!(\"worktree_branch_prefix cannot be empty\");\n    }\n\n    let branch = format!(\"{prefix}/{session_id}\");\n    validate_branch_name(repo_root, &branch).with_context(|| {\n        format!(\n            \"Invalid worktree branch '{branch}' derived from prefix '{}' and session id '{session_id}'\",\n            cfg.worktree_branch_prefix\n        )\n    })?;\n\n    Ok(branch)\n}\n\n/// Remove a worktree and its branch.\npub fn remove(worktree: &WorktreeInfo) -> Result<()> {\n    let repo_root = match base_checkout_path(worktree) {\n        Ok(path) => path,\n        Err(error) => {","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/affaan-m/ECC/blob/01e15490f04e29cfefe3896951f43db46994d8ee/ecc2/src/worktree/mod.rs#L145-L181","documentation":"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.","triggerScenarios":"cfg.worktree_branch_prefix, after .trim().trim_matches('/'), is empty — i.e. the configured value is empty, whitespace-only, or consists solely of slashes.","commonSituations":"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.","solutions":["Set worktree_branch_prefix to a non-empty value (e.g. \"ecc2-sessions\") in the config.","Validate the config at load time and fail fast with a clear, named error before any session starts.","Provide a sensible non-empty default in the Config constructor so an unset key can never reach this path."],"exampleFix":"// before\nlet branch = branch_name_for_session(&session_id, &cfg, repo_root)?;\n\n// after (config side)\nimpl Default for Config {\n    fn default() -> Self {\n        Self { worktree_branch_prefix: \"ecc2-sessions\".to_string(), .. }\n    }\n}\n// load-time guard\nlet prefix = cfg.worktree_branch_prefix.trim().trim_matches('/');\nif prefix.is_empty() {\n    return Err(anyhow::anyhow!(\"config 'worktree_branch_prefix' must be set\"));\n}\nlet branch = branch_name_for_session(&session_id, &cfg, repo_root)?;","handlingStrategy":"validation","validationCode":"fn validate_branch_prefix(cfg: &Config) -> Result<()> {\n    let p = cfg.worktree_branch_prefix.trim().trim_matches('/');\n    if p.is_empty() {\n        return Err(anyhow::anyhow!(\"config 'worktree_branch_prefix' must be non-empty\"));\n    }\n    Ok(())\n}\n\nvalidate_branch_prefix(&cfg)?;\nlet branch = branch_name_for_session(&session_id, &cfg, repo_root)?;","typeGuard":"fn branch_prefix_is_valid(cfg: &Config) -> bool {\n    !cfg.worktree_branch_prefix.trim().trim_matches('/').is_empty()\n}","tryCatchPattern":"match branch_name_for_session(&session_id, &cfg, repo_root) {\n    Ok(branch) => { /* ok */ }\n    Err(e) if e.to_string().contains(\"worktree_branch_prefix cannot be empty\") => {\n        // set cfg.worktree_branch_prefix to a non-empty value and retry\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Give Config::default a non-empty worktree_branch_prefix (e.g. \"ecc2-sessions\").","Validate config at load time and fail fast with a named error.","Document the required key in the config template so it is never left blank."],"tags":["rust","git","worktree","config"],"backgroundTag":null,"analyzedSha":"01e15490f04e29cfefe3896951f43db46994d8ee","analyzedAt":"2026-08-13T00:31:08.655Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}