{"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":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"warning","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/01e15490f04e29cfefe3896951f43db46994d8ee/ecc2/src/worktree/mod.rs#L440-L476","documentation":"commit_staged trims the supplied message and bails if the result is empty. This is the first of two pre-flight checks (the second is staged-changes presence). An empty commit message is almost always a UI or caller bug rather than a user intent.","triggerScenarios":"Passing `\"\"`, `\"   \"`, `\"\\n\\n\"`, or a string of only whitespace to commit_staged. Happens when the commit-message textbox was never populated, the message field was bound to the wrong input, or a template was stripped to nothing by a sanitizer.","commonSituations":"Form submission with no message typed; AI-generated commit message came back empty; trimming/sanitizing layer reduced a placeholder template to whitespace.","solutions":["Validate `message.trim().is_empty()` in the UI/command layer and block submission with a user-facing error.","Provide a sensible default or template the caller must override before reaching commit_staged.","Strip nothing inside commit_staged — trim happens there; ensure upstream code does not pre-strip to empty."],"exampleFix":"// before\nlet hash = commit_staged(&worktree, &raw_input)?;\n\n// after\nlet trimmed = raw_input.trim();\nif trimmed.is_empty() {\n    return Err(anyhow!(\"a commit message is required\"));\n}\nlet hash = commit_staged(&worktree, trimmed)?;","handlingStrategy":"validation","validationCode":"fn ensure_commit_message(msg: &str) -> anyhow::Result<&str> {\n    let trimmed = msg.trim();\n    if trimmed.is_empty() {\n        anyhow::bail!(\"commit message is required\");\n    }\n    Ok(trimmed)\n}\n\nlet msg = ensure_commit_message(raw)?;\nlet hash = commit_staged(&worktree, msg)?;","typeGuard":null,"tryCatchPattern":"match commit_staged(&worktree, raw) {\n    Ok(hash) => Ok(hash),\n    Err(e) if format!(\"{e}\").contains(\"cannot be empty\") => {\n        // prompt user for a message and retry\n        Err(e)\n    }\n    Err(e) => Err(e),\n}","preventionTips":["Make the commit-message field required in the UI with client-side validation.","Default the message to a generated value (e.g. last commit subject + scope) so it is never empty.","Run `msg.trim().is_empty()` checks at the form boundary, not just inside the library."],"tags":["git","worktree","validation","commit","input"],"backgroundTag":null,"analyzedSha":"01e15490f04e29cfefe3896951f43db46994d8ee","analyzedAt":"2026-08-13T00:31:08.655Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}