gitbutlerapp/gitbutler · error

PowerShell directory picker failed

Error message

PowerShell directory picker failed (exit {:?}): {}

What it means

On Windows, `native_pick_directory` runs PowerShell with a `FolderBrowserDialog` (WinForms) to show a folder chooser; empty stdout means the user cancelled (returns Ok(None)). If the PowerShell process exits non-zero, the server raises this error with the exit code and stderr (or "unknown error").

Solutions

  1. Check the exit code/stderr in the message; for execution-policy issues, allow script/command execution for the invoking user.
  2. Run the server in an interactive user session so the WinForms dialog can be displayed (not as a headless service).
  3. Verify PowerShell launches (`pwsh`/`powershell -Command "echo ok"`) and that .NET Framework/WinForms is available.
  4. Skip the native picker and pass the directory path explicitly through the API/CLI.
Defensive patterns

Strategy: fallback

Validate before calling

// Windows: confirm PowerShell can execute commands before requesting the native picker
powershell -NoProfile -Command "echo ok"

Type guard

fn windows_picker_ready(powershell_ok: bool, interactive_session: bool) -> bool {
    powershell_ok && interactive_session
}

Try / catch

match pick_directory().await {
    Err(e) if e.to_string().contains("PowerShell directory picker failed") => {
        let dir = prompt_for_path_manually(); // fallback to text input
    }
    other => other?,
}

Prevention

When it happens

Trigger: Invoking the native directory-pick endpoint on Windows when the PowerShell child process fails: PowerShell not on PATH, execution policy blocking the -Command, WinForms/assembly load failure, or a non-interactive session where the dialog cannot be shown.

Common situations: Running but-server as a service or over SSH with no interactive desktop (STA/dialog unavailable); restricted PowerShell execution policy or Constrained Language Mode; stripped-down Windows installs missing .NET WinForms components.

Related errors


AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18). Data as JSON: /api/errors/468ee21cfecfbfb9. Report an issue: GitHub.

Appendix: source

Thrown at crates/but-server/src/lib.rs:206

    }

    #[cfg(target_os = "windows")]
    {
        // Use the modern IFileOpenDialog via PowerShell (STA is required for
        // any Windows Forms/COM dialog). FolderBrowserDialog is directory-only.
        // The script outputs the selected path on OK, or empty string on cancel.
        // A non-zero exit means PowerShell itself failed (e.g. Add-Type error).
        let output = std::process::Command::new("powershell")
            .args([
                "-NoProfile",
                "-STA",
                "-Command",
                r#"Add-Type -AssemblyName System.Windows.Forms; $f = New-Object System.Windows.Forms.FolderBrowserDialog; $f.Description = 'Select a Git repository'; $f.UseDescriptionForTitle = $true; if ($f.ShowDialog() -eq 'OK') { $f.SelectedPath } else { '' }"#,
            ])
            .output()?;
        if !output.status.success() {
            let stderr = String::from_utf8_lossy(&output.stderr).trim().to_string();
            anyhow::bail!(
                "PowerShell directory picker failed (exit {:?}): {}",
                output.status.code(),
                if stderr.is_empty() {
                    "unknown error"
                } else {
                    &stderr
                }
            );
        }
        let path = String::from_utf8_lossy(&output.stdout).trim().to_string();
        if path.is_empty() {
            return Ok(None);
        }
        Ok(Some(path))
    }

    #[cfg(not(any(target_os = "macos", target_os = "linux", target_os = "windows")))]
    {

View on GitHub (pinned to 58e5313667)