{"record":{"id":"f2e355969bb1a7fe","repo":"moghtech/komodo","slug":"failed-to-get-commit-message","errorCode":null,"errorMessage":"Failed to get commit message | {}","messagePattern":"Failed to get commit message \\| (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"lib/git/src/lib.rs","lineNumber":55,"sourceCode":"  let hash = if hash.status.success() {\n    hash.stdout.trim().to_string()\n  } else {\n    return Err(anyhow!(\n      \"Failed to get short hash | {}\",\n      hash.stderr\n    ));\n  };\n  let message = run_standard_command(\n    \"git log -1 --pretty=%B\",\n    CommandOptions::default()\n      .path(repo_dir)\n      .timeout(Duration::from_secs(2)),\n  )\n  .await;\n  let message = if message.status.success() {\n    message.stdout.trim().to_string()\n  } else {\n    return Err(anyhow!(\n      \"Failed to get commit message | {}\",\n      message.stderr\n    ));\n  };\n  Ok(LatestCommit { hash, message })\n}\n/// returns (Log, commit hash, commit message)\npub async fn get_commit_hash_log(\n  repo_dir: &Path,\n) -> anyhow::Result<(Log, String, String)> {\n  let start_ts = komodo_timestamp();\n  let LatestCommit { hash, message } =\n    get_commit_hash_info(repo_dir).await?;\n  let log = Log {\n    stage: \"Latest Commit\".into(),\n    command: String::from(\n      \"git rev-parse --short HEAD && git log -1 --pretty=%B\",\n    ),","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/moghtech/komodo/blob/780ac68b992094a9fccd5fffb760e0c84fd3c3d1/lib/git/src/lib.rs#L37-L73","documentation":"After fetching the short hash, get_commit_hash_info runs `git log -1 --pretty=%B` to read the latest commit message; a non-zero exit converts the captured stderr into this error. It means git could not read the commit message, typically because the repository has no commits or is not a repository at all.","triggerScenarios":"Calling get_commit_hash_info (via get_commit_hash_log) in a repository with an unborn HEAD (no commits yet) or an invalid repo where `git log -1` fails; also on git subprocess errors or the 2s timeout being exceeded.","commonSituations":"Empty repos right after `git init`; shallow/detached states where git log fails; corrupt repositories; CI checkouts without history (shallow clones of depth issues).","solutions":["Check the stderr after the '|' in the message for git's own diagnostic","Make at least one commit exists in the repository before querying the log","Run `git log -1 --pretty=%B` manually in the directory to reproduce","Re-clone or repair the repository if it is corrupt"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"fn has_log(dir: &Path) -> bool {\n  std::process::Command::new(\"git\").current_dir(dir)\n    .args([\"log\", \"-1\"]).output()\n    .map(|o| o.status.success()).unwrap_or(false)\n}","typeGuard":null,"tryCatchPattern":"match get_commit_hash_log(dir).await {\n  Err(e) if e.to_string().starts_with(\"Failed to get commit message\") => {\n    log::warn!(\"no commit message available: {}\", e); fallback_message()\n  }\n  Ok(c) => c,\n  Err(e) => return Err(e),\n}","preventionTips":["Make an initial commit before querying the log of a fresh repo","Avoid shallow checkouts that break `git log`","Parse the stderr suffix of the message for the underlying git cause"],"tags":["git","subprocess","commit-message","repository-state"],"backgroundTag":"git-command-failed","analyzedSha":"780ac68b992094a9fccd5fffb760e0c84fd3c3d1","analyzedAt":"2026-09-08T10:02:44.861Z","contentChangedAt":"2026-09-08T10:02:44.861Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}