{"record":{"id":"e474edc4c7a25e88","repo":"gitbutlerapp/gitbutler","slug":"valid-hex-prefix","errorCode":null,"errorMessage":"valid hex prefix","messagePattern":"valid hex prefix","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-debug/src/command/graph.rs","lineNumber":64,"sourceCode":"\n    let extra_target = graph_args\n        .extra_target\n        .as_deref()\n        .map(|rev_spec| repo.rev_parse_single(rev_spec))\n        .transpose()?\n        .map(|id| id.detach());\n    let opts = but_graph::init::Options {\n        extra_target_commit_id: extra_target,\n        collect_tags: true,\n        hard_limit: graph_args.hard_limit,\n        commits_limit_hint: graph_args.limit.flatten(),\n        commits_limit_recharge_location: graph_args\n            .limit_extension\n            .iter()\n            .map(|short_hash| {\n                repo.objects\n                    .lookup_prefix(\n                        gix::hash::Prefix::from_hex(short_hash).expect(\"valid hex prefix\"),\n                        None,\n                    )\n                    .unwrap()\n                    .expect(\"object for prefix exists\")\n                    .expect(\"the prefix is unambiguous\")\n            })\n            .collect(),\n        dangerously_skip_postprocessing_for_debugging: graph_args.no_post,\n        worktree_tips: vec![],\n    };\n\n    let graph = match graph_args.ref_name.as_deref() {\n        None => but_graph::Graph::from_head(\n            &repo,\n            &meta,\n            but_core::ref_metadata::ProjectMeta::default(),\n            opts,\n        ),","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/2497b8007aa4a1922dae9a805b32ffe5b5037785/crates/but-debug/src/command/graph.rs#L46-L82","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\n.lookup_prefix(gix::hash::Prefix::from_hex(short_hash).expect(\"valid hex prefix\"), None)\n\n// after\nlet prefix = gix::hash::Prefix::from_hex(short_hash).ok_or_else(|| {\n    anyhow::anyhow!(\"--limit-extension expects a hex object id prefix, got '{short_hash}'\")\n})?;","handlingStrategy":"validation","validationCode":"fn is_valid_hex_prefix(s: &str) -> bool {\n    !s.is_empty()\n        && s.len() <= 40 // SHA-1 length; use 64 for SHA-256 repos\n        && s.bytes().all(|b| b.is_ascii_hexdigit())\n}\n\nif !is_valid_hex_prefix(&short_hash) {\n    return Err(anyhow::anyhow!(\"--limit-extension expects hex, got '{short_hash}'\"));\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["rust","panic","cli-argument","hex","git","debug-command"],"backgroundTag":"invalid-hex-input","analyzedSha":"2497b8007aa4a1922dae9a805b32ffe5b5037785","analyzedAt":"2026-08-17T00:30:25.648Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}