affaan-m/ECC · error

commit message cannot be empty

Error message

commit message cannot be empty

What it means

commit_staged trims the provided message and rejects it if empty. An empty commit message would be rejected by git anyway (or open an editor), so the library validates it up front and returns a clear error. This is pure input validation before any git command runs.

Solutions

  1. Provide a non-empty, meaningful commit message before calling commit_staged.
  2. Validate the message in the UI (disable the commit button when trimmed input is empty).
  3. Trim the message client-side and surface the same validation early for better UX.

Example fix

// before
commit_staged(&worktree, &user_message)?;

// after
let trimmed = user_message.trim();
if trimmed.is_empty() {
    bail!("please enter a commit message");
}
commit_staged(&worktree, trimmed)?;
Defensive patterns

Strategy: validation

Validate before calling

let message = message.trim();
if message.is_empty() {
    return Err(anyhow!("commit message cannot be empty"));
}

Type guard

None

Try / catch

match commit_staged(&worktree, &msg) {
    Ok(hash) => println!("committed {hash}"),
    Err(e) if e.to_string().contains("message cannot be empty") => {
        prompt_user_for_message();
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: Calling commit_staged(worktree, "") or with a whitespace-only string such as " ", or with a message that consists only of newline characters.

Common situations: Commit dialog submitted with an empty message field; message assembled programmatically from missing metadata (e.g. empty AI-generated summary); passing an untrimmed string of spaces from a template.

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 affaan-m/ECC@8321021c54 (2026-09-16). Data as JSON: /api/errors/7f02bd6d8f0ee01f. Report an issue: GitHub.

Appendix: source

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

            if entry.unstaged {
                anyhow::bail!(
                    "cannot reset a staged hunk while the file also has unstaged changes; unstage it first"
                );
            }
            git_apply_patch(
                &worktree.path,
                &["-R", "--index"],
                &hunk.patch,
                "reset selected staged hunk",
            )
        }
    }
}

pub fn commit_staged(worktree: &WorktreeInfo, message: &str) -> Result<String> {
    let message = message.trim();
    if message.is_empty() {
        anyhow::bail!("commit message cannot be empty");
    }
    if !has_staged_changes(worktree)? {
        anyhow::bail!("no staged changes to commit");
    }

    let output = Command::new("git")
        .arg("-C")
        .arg(&worktree.path)
        .args(["commit", "-m", message])
        .output()
        .context("Failed to create commit")?;
    if !output.status.success() {
        let stderr = String::from_utf8_lossy(&output.stderr);
        anyhow::bail!("git commit failed: {stderr}");
    }

    let rev_parse = Command::new("git")
        .arg("-C")

View on GitHub (pinned to 8321021c54)