moghtech/komodo · error · anyhow::Error
Failed to get commit message |
Error message
Failed to get commit message | {} What it means
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.
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
Defensive patterns
Strategy: try-catch
Validate before calling
fn has_log(dir: &Path) -> bool {
std::process::Command::new("git").current_dir(dir)
.args(["log", "-1"]).output()
.map(|o| o.status.success()).unwrap_or(false)
} Try / catch
match get_commit_hash_log(dir).await {
Err(e) if e.to_string().starts_with("Failed to get commit message") => {
log::warn!("no commit message available: {}", e); fallback_message()
}
Ok(c) => c,
Err(e) => return Err(e),
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Empty repos right after `git init`; shallow/detached states where git log fails; corrupt repositories; CI checkouts without history (shallow clones of depth issues).
Understand the failure class
Background: "git command failed": what it means when a tool shells out to git and git exits non-zero — this error's family across 21 libraries.
Related errors
- Failed to get short hash |
- Failed to get remote url | stdout
- Failed: 'git' is not installed or available on $PATH
AI-assisted analysis of moghtech/komodo@780ac68b99 (2026-09-08).
Data as JSON: /api/errors/f2e355969bb1a7fe.
Report an issue: GitHub.
Appendix: source
Thrown at lib/git/src/lib.rs:55
let hash = if hash.status.success() {
hash.stdout.trim().to_string()
} else {
return Err(anyhow!(
"Failed to get short hash | {}",
hash.stderr
));
};
let message = run_standard_command(
"git log -1 --pretty=%B",
CommandOptions::default()
.path(repo_dir)
.timeout(Duration::from_secs(2)),
)
.await;
let message = if message.status.success() {
message.stdout.trim().to_string()
} else {
return Err(anyhow!(
"Failed to get commit message | {}",
message.stderr
));
};
Ok(LatestCommit { hash, message })
}
/// returns (Log, commit hash, commit message)
pub async fn get_commit_hash_log(
repo_dir: &Path,
) -> anyhow::Result<(Log, String, String)> {
let start_ts = komodo_timestamp();
let LatestCommit { hash, message } =
get_commit_hash_info(repo_dir).await?;
let log = Log {
stage: "Latest Commit".into(),
command: String::from(
"git rev-parse --short HEAD && git log -1 --pretty=%B",
),View on GitHub (pinned to 780ac68b99)