gitbutlerapp/gitbutler · warning
valid commit that can be parsed: TODO - allow it to return…
Error message
valid commit that can be parsed: TODO - allow it to return errors?
What it means
The CommitMessageBstr impl for gix::Commit delegates message_bstr() to message_raw(), which returns a Result, and unwraps it with expect. The assumption is that a loaded commit object can always have its message decoded; if the underlying object read/decode fails, this panics. The TODO acknowledges it should return errors instead.
Solutions
- Change the trait method or call site to propagate the error (make message_bstr fallible or add a try_ variant)
- Fall back to an empty/default label when the message cannot be read
- Run `git fsck` on the repository to find and repair corrupt objects
Example fix
// before
fn message_bstr(&self) -> &BStr {
self.message_raw()
.expect("valid commit that can be parsed: TODO - allow it to return errors?")
}
// after
fn message_bstr(&self) -> anyhow::Result<&BStr> {
Ok(self.message_raw()?)
} Defensive patterns
Strategy: fallback
Validate before calling
// Check the object is readable before extracting the title: let label = commit.message_raw().ok().map(commit_title).unwrap_or_default();
Type guard
fn has_readable_message(commit: &gix::Commit) -> bool {
commit.message_raw().is_ok()
} Try / catch
// At call sites like commit_title_to_merge_conflict_label, fall back:
let title = commit.message_raw().map_or_else(
|_| "(unreadable commit message)".to_string(),
|m| title_from_message(m),
); Prevention
- Run `git fsck` when commit objects fail to decode
- Avoid panicking helpers on lazy object reads; propagate errors through the label builder
- Clone/fetch fresh copies of repositories whose objects appear corrupt
When it happens
Trigger: Calling message_bstr() (e.g. via commit_title_to_merge_conflict_label when generating a merge-conflict label from a commit title) on a commit whose message_raw() fails — corrupt/missing object data or undecodable bytes.
Common situations: Repository object corruption or truncation; reading commits from an object database that fails lazily; labels for merge conflicts built from unusual commits.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- BUG: value must be valid ref name
- BUG: we have to avoid using these legacy types
- no illformed UTF8
- repo access failed
- write to memory succeeds
AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18).
Data as JSON: /api/errors/111c92aa78b5b8e8.
Report an issue: GitHub.
Appendix: source
Thrown at crates/gitbutler-commit/src/commit_ext.rs:31
/// Obtain the commit-message as bytes, but without assuming any encoding.
fn message_bstr(&self) -> &BStr;
}
impl CommitExt for gix::Commit<'_> {
fn change_id(&self) -> Option<ChangeId> {
let commit = self.decode().ok()?;
Headers::try_from_commit_headers(|| commit.extra_headers())?.change_id
}
fn is_conflicted(&self) -> bool {
but_core::Commit::try_from(self.clone()).is_ok_and(|commit| commit.is_conflicted())
}
}
impl CommitMessageBstr for gix::Commit<'_> {
fn message_bstr(&self) -> &BStr {
self.message_raw()
.expect("valid commit that can be parsed: TODO - allow it to return errors?")
}
}
View on GitHub (pinned to 58e5313667)