nikivdev/code · error
clipboard not supported on this platform
Error message
clipboard not supported on this platform
What it means
`copy_to_clipboard` implements platform-specific clipboard access via `#[cfg]` for macOS (pbcopy) and Linux (xclip/xsel/wl-copy style). On any other target OS, the compiled-in fallback simply bails with 'clipboard not supported on this platform'. It is a compile-time gate, not a runtime capability probe.
Source
Thrown at src/hash.rs:104
Err(_) => Command::new("xsel")
.arg("--clipboard")
.arg("--input")
.stdin(std::process::Stdio::piped())
.spawn()
.context("failed to spawn xclip or xsel")?,
};
if let Some(stdin) = child.stdin.as_mut() {
use std::io::Write;
stdin.write_all(text.as_bytes())?;
}
child.wait()?;
}
#[cfg(not(any(target_os = "macos", target_os = "linux")))]
{
bail!("clipboard not supported on this platform");
}
Ok(())
}
View on GitHub (pinned to a747e741ae)
Solutions
- Use a supported platform (macOS or Linux) where the cfg-gated implementations compile in
- On Windows, contribute or apply a cfg arm using `clip.exe` (`cmd /c clip` or PowerShell Set-Clipboard)
- In callers, treat this as an expected failure and degrade gracefully (print the value instead of copying)
- Check the actual compiled target with `rustc -vV | grep host` if you believe you're on Linux/macOS
Example fix
// before
#[cfg(not(any(target_os = "macos", target_os = "linux")))]
{
bail!("clipboard not supported on this platform");
}
// after
#[cfg(target_os = "windows")]
{
let mut child = Command::new("cmd").args(["/C", "clip"]).stdin(Stdio::piped()).spawn()?;
child.stdin.take().unwrap().write_all(text.as_bytes())?;
child.wait()?;
}
#[cfg(not(any(target_os = "macos", target_os = "linux", target_os = "windows")))]
{
bail!("clipboard not supported on this platform");
} Defensive patterns
Strategy: fallback
Validate before calling
#[cfg(any(target_os = "macos", target_os = "linux"))]
const CLIPBOARD_SUPPORTED: bool = true;
#[cfg(not(any(target_os = "macos", target_os = "linux")))]
const CLIPBOARD_SUPPORTED: bool = false;
if !CLIPBOARD_SUPPORTED {
eprintln!("clipboard unavailable; printing value instead");
} Type guard
fn clipboard_supported() -> bool {
cfg!(any(target_os = "macos", target_os = "linux"))
} Try / catch
match copy_to_clipboard(text) {
Err(e) if e.to_string().contains("clipboard not supported") => {
println!("{text}"); // graceful degradation: print instead of copy
}
Err(e) => return Err(e),
Ok(()) => {}
} Prevention
- Compile-check for all target platforms in CI (cargo check --target matrix)
- Detect platform at startup and disable clipboard features early with a clear message
- Provide a non-clipboard output path (print to stdout / write to file)
- Document platform requirements in the README
When it happens
Trigger: Running the binary compiled for (or `cfg`-targeted at) an OS other than macOS or Linux — e.g. Windows, or a custom/unknown target — and invoking a code path that calls `copy_to_clipboard`.
Common situations: Building/running on Windows natively; cross-compiling for an embedded or BSD target; a CI runner on a non-supported platform invoking the copy step.
Understand the failure class
Background: "unsupported platform" / "not supported on this platform" errors: what they mean and how to fix them — this error's family across 47 libraries.
Related errors
- clipboard not supported on this platform
- Flow Codex wrapper is missing at {}; build or sync Flow firs
- codex skill-eval launchd install failed: {}
- enable-global is only supported for Codex sessions; use `f c
- pbcopy exited with status {}
AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01).
Data as JSON: /api/errors/5a55be9107f6becb.
Report an issue: GitHub.