{"record":{"id":"4278c04ea8247c27","repo":"gitbutlerapp/gitbutler","slug":"failed-to-resolve-path-to-hunk","errorCode":null,"errorMessage":"Failed to resolve path to hunk","messagePattern":"Failed to resolve path to hunk","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but/src/command/open.rs","lineNumber":70,"sourceCode":"        repo: &gix::Repository,\n        uncommitted: &UncommittedHunkOrFile,\n    ) -> anyhow::Result<Self> {\n        Self::try_from_hunk(\n            repo,\n            &uncommitted.hunks.first().hunk,\n            uncommitted.is_entire_file,\n        )\n    }\n\n    /// Try to create an [`Openable`] from a hunk.\n    fn try_from_hunk(\n        repo: &gix::Repository,\n        hunk: &SingleHunk,\n        is_entire_file: bool,\n    ) -> anyhow::Result<Self> {\n        let path = repo\n            .workdir_path(hunk.path.as_bstr())\n            .ok_or_else(|| anyhow::anyhow!(\"Failed to resolve path to hunk\"))?;\n\n        let openable = match (is_entire_file, &hunk.hunk_header, hunk.line_nums()) {\n            (false, Some(hunk_header), Some((line_nums_added, line_nums_removed))) => {\n                Openable::Hunk(Hunk {\n                    // Truncate line numbers - the probability of exceeding a u32 is infinitesimally small.\n                    line_nums_added: line_nums_added\n                        .iter()\n                        .map(|n| (*n).min(u32::MAX as usize) as u32)\n                        .collect(),\n                    line_nums_removed: line_nums_removed\n                        .iter()\n                        .map(|n| (*n).min(u32::MAX as usize) as u32)\n                        .collect(),\n                    old_start: hunk_header.old_start,\n                    new_start: hunk_header.new_start,\n                    path,\n                })\n            }","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but/src/command/open.rs#L52-L88","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if repo.workdir().is_none() || hunk.path.is_empty() {\n    anyhow::bail!(\"cannot resolve hunk path '{}' in this repository\", hunk.path);\n}","typeGuard":"fn resolvable(repo: &gix::Repository, path: &bstr::BStr) -> bool {\n    repo.workdir_path(path).is_some()\n}","tryCatchPattern":"match Openable::try_from_hunk(repo, hunk, entire) {\n    Err(e) if e.to_string().contains(\"Failed to resolve path to hunk\") =>\n        eprintln!(\"Skipping unresolvable hunk path\"),\n    other => other?,\n}","preventionTips":["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."],"tags":["git","path-resolution","hunk"],"backgroundTag":"file-not-found","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}