{"record":{"id":"356d6c7fcaa9b988","repo":"tonhowtf/omniget","slug":"powershell-set-clipboard-failed","errorCode":null,"errorMessage":"PowerShell Set-Clipboard failed: {}","messagePattern":"PowerShell Set-Clipboard failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/clipboard.rs","lineNumber":166,"sourceCode":"        \"No clipboard tool found (tried xclip, xsel, wl-copy)\"\n    ))\n}\n\n#[cfg(target_os = \"windows\")]\nasync fn copy_file_windows(path: &str) -> anyhow::Result<()> {\n    let ps_script = format!(\"Set-Clipboard -LiteralPath '{}'\", path.replace('\\'', \"''\"));\n\n    let output = tokio::task::spawn_blocking(move || {\n        crate::core::process::std_command(\"powershell\")\n            .args([\"-NoProfile\", \"-NonInteractive\", \"-Command\", &ps_script])\n            .output()\n    })\n    .await\n    .map_err(|e| anyhow::anyhow!(\"spawn_blocking failed: {}\", e))??;\n\n    if !output.status.success() {\n        let stderr = String::from_utf8_lossy(&output.stderr);\n        return Err(anyhow::anyhow!(\n            \"PowerShell Set-Clipboard failed: {}\",\n            stderr\n        ));\n    }\n\n    tracing::info!(\"[clipboard] copied file to clipboard (Windows): {}\", path);\n    Ok(())\n}\n","sourceCodeStart":148,"sourceCodeEnd":175,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/clipboard.rs#L148-L175","documentation":"After copy_file_windows runs the PowerShell Set-Clipboard script, it checks output.status. If the PowerShell process exits non-zero, the captured stderr is surfaced as \"PowerShell Set-Clipboard failed: {stderr}\". This means the OS-level clipboard write genuinely failed or the script itself errored.","triggerScenarios":"powershell -NoProfile -NonInteractive -Command <ps_script> exits with a non-zero status while copying the file to the Windows clipboard — e.g. script parse errors, STA threading issues, or clipboard access being blocked.","commonSituations":"Windows PowerShell execution policy or Constrained Language Mode blocking the script; clipboard locked by another application; running in a non-interactive service session (Session 0) with no clipboard access; older PowerShell versions lacking Set-Clipboard.","solutions":["Read the stderr in the error message — it names the actual PowerShell failure (syntax, execution policy, Set-Clipboard availability).","Run the exact ps_script manually in PowerShell to reproduce and debug the failure.","For services/CI without an interactive desktop, run in a user session or use a different clipboard API (e.g. arboard/clipboard-win crates).","Ensure Windows PowerShell 5.0+ (Set-Clipboard exists since PS 5.0); on very old systems use the .NET Windows.Forms Clipboard API in the script."],"exampleFix":"// before\nif !output.status.success() {\n    let stderr = String::from_utf8_lossy(&output.stderr);\n    return Err(anyhow::anyhow!(\"PowerShell Set-Clipboard failed: {}\", stderr));\n}\n\n// after\nif !output.status.success() {\n    let stderr = String::from_utf8_lossy(&output.stderr);\n    let stdout = String::from_utf8_lossy(&output.stdout);\n    tracing::error!(\"[clipboard] PS stdout: {}\", stdout);\n    return Err(anyhow::anyhow!(\"PowerShell Set-Clipboard failed (exit {:?}): {}\", output.status.code(), stderr));\n}","handlingStrategy":"try-catch","validationCode":"// Validate the PowerShell script compiles before running the real copy\nlet check = std::process::Command::new(\"powershell\")\n    .args([\"-NoProfile\", \"-NonInteractive\", \"-Command\", \"$ErrorActionPreference='Stop'; Set-Clipboard -Value 'test'\"])\n    .output()?;\nif !check.status.success() {\n    eprintln!(\"PowerShell Set-Clipboard unavailable: {}\", String::from_utf8_lossy(&check.stderr));\n}","typeGuard":null,"tryCatchPattern":"match copy_file_to_clipboard(path).await {\n    Err(e) if e.to_string().contains(\"PowerShell Set-Clipboard failed\") => {\n        log::error!(\"PowerShell clipboard error, check stderr in message: {}\", e);\n        // surface stderr details to the user / try alternate clipboard API\n    }\n    other => other?,\n}","preventionTips":["Require Windows PowerShell 5.0+ (Set-Clipboard availability)","Test the ps_script manually before shipping","Avoid running clipboard code in Session 0 / service contexts","Log stdout alongside stderr to diagnose script failures","Consider a native clipboard crate (arboard) instead of shelling out to PowerShell"],"tags":["clipboard","windows","powershell","process-exit-nonzero"],"backgroundTag":"command-not-found","analyzedSha":"8600b91f4246848bac346874daa9e61c1fc5677a","analyzedAt":"2026-09-12T14:29:19.317Z","contentChangedAt":"2026-09-12T14:29:19.317Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}