{"record":{"id":"7f02bd6d8f0ee01f","repo":"affaan-m/ECC","slug":"commit-message-cannot-be-empty","errorCode":null,"errorMessage":"commit message cannot be empty","messagePattern":"commit message cannot be empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ecc2/src/worktree/mod.rs","lineNumber":458,"sourceCode":"            if entry.unstaged {\n                anyhow::bail!(\n                    \"cannot reset a staged hunk while the file also has unstaged changes; unstage it first\"\n                );\n            }\n            git_apply_patch(\n                &worktree.path,\n                &[\"-R\", \"--index\"],\n                &hunk.patch,\n                \"reset selected staged hunk\",\n            )\n        }\n    }\n}\n\npub fn commit_staged(worktree: &WorktreeInfo, message: &str) -> Result<String> {\n    let message = message.trim();\n    if message.is_empty() {\n        anyhow::bail!(\"commit message cannot be empty\");\n    }\n    if !has_staged_changes(worktree)? {\n        anyhow::bail!(\"no staged changes to commit\");\n    }\n\n    let output = Command::new(\"git\")\n        .arg(\"-C\")\n        .arg(&worktree.path)\n        .args([\"commit\", \"-m\", message])\n        .output()\n        .context(\"Failed to create commit\")?;\n    if !output.status.success() {\n        let stderr = String::from_utf8_lossy(&output.stderr);\n        anyhow::bail!(\"git commit failed: {stderr}\");\n    }\n\n    let rev_parse = Command::new(\"git\")\n        .arg(\"-C\")","sourceCodeStart":440,"sourceCodeEnd":476,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/ecc2/src/worktree/mod.rs#L440-L476","documentation":"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.","triggerScenarios":"Calling commit_staged(worktree, \"\") or with a whitespace-only string such as \"   \", or with a message that consists only of newline characters.","commonSituations":"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.","solutions":["Provide a non-empty, meaningful commit message before calling commit_staged.","Validate the message in the UI (disable the commit button when trimmed input is empty).","Trim the message client-side and surface the same validation early for better UX."],"exampleFix":"// before\ncommit_staged(&worktree, &user_message)?;\n\n// after\nlet trimmed = user_message.trim();\nif trimmed.is_empty() {\n    bail!(\"please enter a commit message\");\n}\ncommit_staged(&worktree, trimmed)?;","handlingStrategy":"validation","validationCode":"let message = message.trim();\nif message.is_empty() {\n    return Err(anyhow!(\"commit message cannot be empty\"));\n}","typeGuard":"None","tryCatchPattern":"match commit_staged(&worktree, &msg) {\n    Ok(hash) => println!(\"committed {hash}\"),\n    Err(e) if e.to_string().contains(\"message cannot be empty\") => {\n        prompt_user_for_message();\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Trim and validate the commit message before calling the API.","Disable the commit button while the message input is empty/whitespace.","When generating messages programmatically, fall back to a placeholder if the generator returns empty."],"tags":["git","validation","empty-input"],"backgroundTag":"empty-required-field","analyzedSha":"8321021c54d670126ce3b2969d5deb880b4b0c2a","analyzedAt":"2026-09-16T10:08:13.343Z","contentChangedAt":"2026-09-16T10:08:13.343Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}