gitbutlerapp/gitbutler · error
valid hex prefix
Error message
valid hex prefix
What it means
Panic in the 'but debug graph' command: a value passed via --limit-extension failed gix::hash::Prefix::from_hex, which returns None for strings containing characters outside 0-9a-f/A-F, for empty strings, or for input longer than the hash length. The debug command asserts validity with expect instead of reporting a parse error, so malformed input aborts the process.
Source
Thrown at crates/but-debug/src/command/graph.rs:64
let extra_target = graph_args
.extra_target
.as_deref()
.map(|rev_spec| repo.rev_parse_single(rev_spec))
.transpose()?
.map(|id| id.detach());
let opts = but_graph::init::Options {
extra_target_commit_id: extra_target,
collect_tags: true,
hard_limit: graph_args.hard_limit,
commits_limit_hint: graph_args.limit.flatten(),
commits_limit_recharge_location: graph_args
.limit_extension
.iter()
.map(|short_hash| {
repo.objects
.lookup_prefix(
gix::hash::Prefix::from_hex(short_hash).expect("valid hex prefix"),
None,
)
.unwrap()
.expect("object for prefix exists")
.expect("the prefix is unambiguous")
})
.collect(),
dangerously_skip_postprocessing_for_debugging: graph_args.no_post,
worktree_tips: vec![],
};
let graph = match graph_args.ref_name.as_deref() {
None => but_graph::Graph::from_head(
&repo,
&meta,
but_core::ref_metadata::ProjectMeta::default(),
opts,
),View on GitHub (pinned to 2497b8007a)
Solutions
- Pass a real abbreviated commit id, e.g. the output of 'git rev-parse --short HEAD'
- Strip non-hex characters (branch names, 'g' prefixes) before passing the value
- Maintainer: replace the expect with a bad_input error echoing the offending value
Example fix
// before
.lookup_prefix(gix::hash::Prefix::from_hex(short_hash).expect("valid hex prefix"), None)
// after
let prefix = gix::hash::Prefix::from_hex(short_hash).ok_or_else(|| {
anyhow::anyhow!("--limit-extension expects a hex object id prefix, got '{short_hash}'")
})?; Defensive patterns
Strategy: validation
Validate before calling
fn is_valid_hex_prefix(s: &str) -> bool {
!s.is_empty()
&& s.len() <= 40 // SHA-1 length; use 64 for SHA-256 repos
&& s.bytes().all(|b| b.is_ascii_hexdigit())
}
if !is_valid_hex_prefix(&short_hash) {
return Err(anyhow::anyhow!("--limit-extension expects hex, got '{short_hash}'"));
} Prevention
- Feed the flag from 'git rev-parse --short HEAD' output rather than hand-typed values
- Reject obvious non-hex values (branch names, 'g'-prefixed describe output) at the CLI boundary
- Remember this is a debug command: panics here are loud by design; validate inputs in wrappers
When it happens
Trigger: Running 'but debug graph --limit-extension main' (a ref name, not hex); a short hash containing a 'g' (as in git describe output) or any non-hex character; an empty string; a value longer than 40 hex chars on a SHA-1 repository.
Common situations: Confusing branch names with object-id prefixes; pasting from 'git describe' output that embeds a 'g' before the hash; scripts forwarding unvalidated user input into the debug command.
Related errors
- object for prefix exists
- repo access failed
- 'dot' (graphviz) must be installed on the system
- failed to create app settings
- all help topics have clap command metadata
AI-assisted analysis of gitbutlerapp/gitbutler@2497b8007a (2026-08-17).
Data as JSON: /api/errors/e474edc4c7a25e88.
Report an issue: GitHub.