gitbutlerapp/gitbutler · warning
Invalid trailer format, expected `key: value`
Error message
Invalid trailer format, expected `key: value`
What it means
CommitTrailer::from_str parses a trailer string that must have the shape `key: value`. If the string contains no colon, splitn(2, ':') yields only one part and this anyhow error is raised. The parser is intentionally strict: trailers without a colon cannot be split into a key and value.
Solutions
- Ensure each trailer contains a colon separating key and value before parsing
- Filter out empty/malformed lines before calling from_str
- Fix the commit message trailer itself with `git commit --amend` or `git interpret-trailers`
Example fix
// before let t: CommitTrailer = "Reviewed-by Alice".parse()?; // after let t: CommitTrailer = "Reviewed-by: Alice".parse()?; // key: value
Defensive patterns
Strategy: validation
Validate before calling
fn looks_like_trailer(s: &str) -> bool { s.split_once(':').is_some() }
let trailers: Result<Vec<_>, _> = lines.filter(|l| looks_like_trailer(l))
.map(CommitTrailer::from_str).collect(); Type guard
fn parse_trailer(s: &str) -> Option<CommitTrailer> {
let (k, v) = s.split_once(':')?;
Some(CommitTrailer::new(k.trim(), v.trim()))
} Try / catch
match s.parse::<CommitTrailer>() {
Ok(t) => t,
Err(e) if e.to_string().contains("key: value") => skip_or_log(s),
Err(e) => return Err(e),
} Prevention
- Format trailers strictly as `key: value` (colon required)
- Skip blank lines when iterating commit-message lines
- Use `git interpret-trailers` output as the source of trailer strings
When it happens
Trigger: Passing a trailer string without a colon to CommitTrailer::from_str / str::parse::<CommitTrailer>() — e.g. "Signed-off-by John" instead of "Signed-off-by: John <x@y.z>" or an empty/whitespace-only token from splitting a commit message.
Common situations: Hand-written trailer lists; splitting trailers on newline where a blank line sneaks in; reading trailers from external tooling that omits the colon.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- commit prefix ' ' is ambiguous
- commit ' ' is not part of the editable divergence
- Could not find range from
- Expected `project_id` to be a ProjectHandle, got
- Expected `project_id` to be either a ProjectHandle or a…
AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18).
Data as JSON: /api/errors/c139e2951c4b9de6.
Report an issue: GitHub.
Appendix: source
Thrown at crates/but-core/src/snapshot/mod.rs:57
pub key: String,
/// Trailer value.
pub value: String,
}
impl Display for CommitTrailer {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
let escaped_value = self.value.replace('\n', "\\n");
write!(f, "{}: {}", self.key, escaped_value)
}
}
impl FromStr for CommitTrailer {
type Err = anyhow::Error;
fn from_str(s: &str) -> anyhow::Result<Self, Self::Err> {
let mut parts = s.splitn(2, ':');
let (Some(key), Some(value)) = (parts.next(), parts.next()) else {
return Err(anyhow!("Invalid trailer format, expected `key: value`"));
};
let unescaped_value = value.trim().replace("\\n", "\n");
Ok(Self {
key: key.trim().to_string(),
value: unescaped_value,
})
}
}
/// Metadata attached to [`Commit`]s holding snapshots.
pub struct CommitMetadata {
/// The name of the operation that created the commit.
/// This is an internal string.
pub operation: String,
/// The title of the commit for user consumption, typically created using information from `trailers`.
pub title: String,
/// Properties to be stored with the commit.
pub trailers: Vec<CommitTrailer>,View on GitHub (pinned to 58e5313667)