gitbutlerapp/gitbutler · error
Failed to resolve path to hunk
Error message
Failed to resolve path to hunk
What it means
When converting a diff hunk into an openable item, the CLI resolves the hunk's relative file path against the repository working directory via `gix::Repository::workdir_path`. This error is thrown when that resolution returns `None`, meaning the path cannot be anchored to a working tree.
Solutions
- Run the command inside a normal (non-bare) repository with a working tree.
- Check the hunk's `path` value in the diff input for emptiness or malformed characters and fix the source diff.
- Update or re-run the workspace/diff computation so hunks carry valid repo-relative paths.
Defensive patterns
Strategy: validation
Validate before calling
if repo.workdir().is_none() || hunk.path.is_empty() {
anyhow::bail!("cannot resolve hunk path '{}' in this repository", hunk.path);
} Type guard
fn resolvable(repo: &gix::Repository, path: &bstr::BStr) -> bool {
repo.workdir_path(path).is_some()
} Try / catch
match Openable::try_from_hunk(repo, hunk, entire) {
Err(e) if e.to_string().contains("Failed to resolve path to hunk") =>
eprintln!("Skipping unresolvable hunk path"),
other => other?,
} Prevention
- Ensure the repo used for diff parsing has a working tree.
- Sanitize/normalize hunk paths when building the diff input.
- Regenerate hunks from a fresh diff if paths look stale.
When it happens
Trigger: Calling `Openable::try_from_hunk` with a repository that has no workdir (bare), or with a `SingleHunk.path` that is empty/non-UTF8/otherwise rejected by `workdir_path`, so no absolute path can be produced.
Common situations: Running the `but open` flow against a bare repository; a hunk whose recorded path is missing or malformed after a diff parse; path containing unusual encodings that gix refuses to join.
Understand the failure class
Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.
Related errors
- Aborting due to empty branch name
- Ad-hoc (single-branch) branch moves are not supported…
- An octopus merge commits must have at least two parents
- another pre-commit hook is already using the repository…
- askpass broker must be initialized
AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18).
Data as JSON: /api/errors/4278c04ea8247c27.
Report an issue: GitHub.
Appendix: source
Thrown at crates/but/src/command/open.rs:70
repo: &gix::Repository,
uncommitted: &UncommittedHunkOrFile,
) -> anyhow::Result<Self> {
Self::try_from_hunk(
repo,
&uncommitted.hunks.first().hunk,
uncommitted.is_entire_file,
)
}
/// Try to create an [`Openable`] from a hunk.
fn try_from_hunk(
repo: &gix::Repository,
hunk: &SingleHunk,
is_entire_file: bool,
) -> anyhow::Result<Self> {
let path = repo
.workdir_path(hunk.path.as_bstr())
.ok_or_else(|| anyhow::anyhow!("Failed to resolve path to hunk"))?;
let openable = match (is_entire_file, &hunk.hunk_header, hunk.line_nums()) {
(false, Some(hunk_header), Some((line_nums_added, line_nums_removed))) => {
Openable::Hunk(Hunk {
// Truncate line numbers - the probability of exceeding a u32 is infinitesimally small.
line_nums_added: line_nums_added
.iter()
.map(|n| (*n).min(u32::MAX as usize) as u32)
.collect(),
line_nums_removed: line_nums_removed
.iter()
.map(|n| (*n).min(u32::MAX as usize) as u32)
.collect(),
old_start: hunk_header.old_start,
new_start: hunk_header.new_start,
path,
})
}View on GitHub (pinned to 58e5313667)