{"record":{"id":"3fa261e6fab06874","repo":"gitbutlerapp/gitbutler","slug":"directory-picker-failed-exit-code","errorCode":null,"errorMessage":"directory picker failed (exit {code}): {}","messagePattern":"directory picker failed \\(exit (.+?)\\): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-server/src/lib.rs","lineNumber":174,"sourceCode":"            .output()\n            .or_else(|_| {\n                std::process::Command::new(\"kdialog\")\n                    .args([\n                        \"--getexistingdirectory\",\n                        \".\",\n                        \"--title\",\n                        \"Select a Git repository\",\n                    ])\n                    .output()\n            })?;\n        if !output.status.success() {\n            // zenity exits 1 on cancel, kdialog exits 1 on cancel\n            let code = output.status.code().unwrap_or(-1);\n            if code == 1 {\n                return Ok(None);\n            }\n            let stderr = String::from_utf8_lossy(&output.stderr).trim().to_string();\n            anyhow::bail!(\n                \"directory picker failed (exit {code}): {}\",\n                if stderr.is_empty() {\n                    \"unknown error\"\n                } else {\n                    &stderr\n                }\n            );\n        }\n        let path = String::from_utf8_lossy(&output.stdout).trim().to_string();\n        if path.is_empty() {\n            return Ok(None);\n        }\n        Ok(Some(path))\n    }\n\n    #[cfg(target_os = \"windows\")]\n    {\n        // Use the modern IFileOpenDialog via PowerShell (STA is required for","sourceCodeStart":156,"sourceCodeEnd":192,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-server/src/lib.rs#L156-L192","documentation":"On Linux, `native_pick_directory` uses `zenity` (with `kdialog` as fallback) to show a folder chooser. Exit code 1 is treated as user cancellation and returns Ok(None); any other non-zero exit produces this error with the process exit code and trimmed stderr (or \"unknown error\").","triggerScenarios":"Invoking the native directory-pick endpoint on Linux when zenity/kdialog exits with a code other than 0 or 1 — e.g. the dialog tool is installed but cannot open a display, crashes, or is invoked with invalid options in an unsupported desktop environment.","commonSituations":"Running on a headless Linux box or in a session without DISPLAY/WAYLAND_DISPLAY so zenity fails to open a window; a minimal install where the desktop portal is unavailable; unusual exit codes from wrappers around zenity.","solutions":["Read the exit code and stderr in the message; for display errors, set DISPLAY/WAYLAND_DISPLAY or run inside a graphical session.","Install a working dialog backend (`zenity` or `kdialog`) and verify it runs, e.g. `zenity --version`.","Bypass the native picker by providing the path directly through the API/CLI parameter.","If the tool genuinely exited 1 on cancel but wasn't caught, treat the operation as cancelled and retry or ask the user again."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"// Linux: verify a dialog backend and a display exist before requesting the native picker\ncommand -v zenity || command -v kdialog; [ -n \"$DISPLAY\" -o -n \"$WAYLAND_DISPLAY\" ] && echo ok","typeGuard":"fn linux_picker_ready(has_zenity: bool, has_kdialog: bool, has_display: bool) -> bool {\n    has_display && (has_zenity || has_kdialog)\n}","tryCatchPattern":"match pick_directory().await {\n    Err(e) if e.to_string().contains(\"directory picker failed\") => {\n        let dir = prompt_for_path_manually(); // fallback to text input\n    }\n    other => other?,\n}","preventionTips":["Install zenity or kdialog and confirm it launches in the target environment.","Ensure DISPLAY/WAYLAND_DISPLAY is set and the process runs in a graphical session.","Offer a manual path-entry fallback so headless environments still work.","Remember exit code 1 means the user cancelled (Ok(None)), not a failure."],"tags":["linux","zenity","native-dialog","display"],"backgroundTag":"command-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"}