Hmbown/CodeWhale · error
worktree branch must not be empty
Error message
worktree branch must not be empty
What it means
Input validation in `provision_worktree` (crates/lane/src/worktree.rs): the `WorktreeProvision.branch` field is empty or whitespace-only. A worktree needs a branch name to `git worktree add -b`, so the library fails fast before touching the filesystem or git.
Solutions
- Populate `branch` with a non-empty name before calling provision_worktree (e.g. derive it from the lane id).
- Validate/trim the lane name or config field that feeds `branch` at load time.
- Provide an explicit branch in the lane spec instead of relying on defaults.
Example fix
// before
WorktreeProvision { branch: String::new(), .. }
// after
WorktreeProvision { branch: format!("lane/{}", lane_id), .. } Defensive patterns
Strategy: validation
Validate before calling
let branch = spec.branch.trim(); anyhow::ensure!(!branch.is_empty(), "branch required before provisioning worktree");
Type guard
fn valid_branch(b: &str) -> bool { !b.trim().is_empty() } Prevention
- Derive branch from lane id with a non-empty fallback at construction time.
- Validate config fields feeding WorktreeProvision at load time.
- Never pass String::default() as a branch.
When it happens
Trigger: Calling `provision_worktree` with `WorktreeProvision { branch: "" }`, a branch of only spaces, or a branch derived from an unset/empty lane name or config field.
Common situations: Lane name interpolated from an env var that is unset; a config file where `branch` is omitted and defaults to `String::default()`; programmatic provisioning where the branch was supposed to be derived from user input that arrived empty.
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
- baseline provenance must identify a clean source tree
- baseline provenance needs an exact source SHA
- expected revision must be an exact 40-character Git SHA
- gh pr view did not return exact base and head commit IDs
- git worktree add failed for branch
AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22).
Data as JSON: /api/errors/c06ef52273452f97.
Report an issue: GitHub.
Appendix: source
Thrown at crates/lane/src/worktree.rs:33
pub repo_root: PathBuf,
/// Branch to create (from `base_ref`).
pub branch: String,
/// Directory for the new worktree (created by `git worktree add`).
pub path: PathBuf,
/// Base ref to branch from (default `HEAD`).
pub base_ref: Option<String>,
}
#[derive(Debug, Clone)]
pub struct ProvisionedWorktree {
pub path: PathBuf,
pub branch: String,
}
/// Create a git worktree + branch for a lane.
pub fn provision_worktree(spec: &WorktreeProvision) -> Result<ProvisionedWorktree> {
if spec.branch.trim().is_empty() {
bail!("worktree branch must not be empty");
}
if !spec.repo_root.exists() {
bail!("repo root does not exist: {}", spec.repo_root.display());
}
if let Some(parent) = spec.path.parent() {
fs::create_dir_all(parent)
.with_context(|| format!("create worktree parent {}", parent.display()))?;
}
let base = spec.base_ref.as_deref().unwrap_or("HEAD");
// Capture git output instead of inheriting the caller's terminal. Runtime
// callers include the raw-mode TUI launch screen, where even one inherited
// progress/error line corrupts the alternate-screen buffer.
let output = Command::new("git")
.current_dir(&spec.repo_root)
.args([
"worktree",
"add",
"-b",View on GitHub (pinned to 73e0f67d83)