{"record":{"id":"5a55be9107f6becb","repo":"nikivdev/code","slug":"clipboard-not-supported-on-this-platform-5a55be","errorCode":null,"errorMessage":"clipboard not supported on this platform","messagePattern":"clipboard not supported on this platform","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/hash.rs","lineNumber":104,"sourceCode":"            Err(_) => Command::new(\"xsel\")\n                .arg(\"--clipboard\")\n                .arg(\"--input\")\n                .stdin(std::process::Stdio::piped())\n                .spawn()\n                .context(\"failed to spawn xclip or xsel\")?,\n        };\n\n        if let Some(stdin) = child.stdin.as_mut() {\n            use std::io::Write;\n            stdin.write_all(text.as_bytes())?;\n        }\n\n        child.wait()?;\n    }\n\n    #[cfg(not(any(target_os = \"macos\", target_os = \"linux\")))]\n    {\n        bail!(\"clipboard not supported on this platform\");\n    }\n\n    Ok(())\n}\n","sourceCodeStart":86,"sourceCodeEnd":109,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/hash.rs#L86-L109","documentation":"`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.","triggerScenarios":"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`.","commonSituations":"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.","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"],"exampleFix":"// before\n#[cfg(not(any(target_os = \"macos\", target_os = \"linux\")))]\n{\n    bail!(\"clipboard not supported on this platform\");\n}\n// after\n#[cfg(target_os = \"windows\")]\n{\n    let mut child = Command::new(\"cmd\").args([\"/C\", \"clip\"]).stdin(Stdio::piped()).spawn()?;\n    child.stdin.take().unwrap().write_all(text.as_bytes())?;\n    child.wait()?;\n}\n#[cfg(not(any(target_os = \"macos\", target_os = \"linux\", target_os = \"windows\")))]\n{\n    bail!(\"clipboard not supported on this platform\");\n}","handlingStrategy":"fallback","validationCode":"#[cfg(any(target_os = \"macos\", target_os = \"linux\"))]\nconst CLIPBOARD_SUPPORTED: bool = true;\n#[cfg(not(any(target_os = \"macos\", target_os = \"linux\")))]\nconst CLIPBOARD_SUPPORTED: bool = false;\nif !CLIPBOARD_SUPPORTED {\n    eprintln!(\"clipboard unavailable; printing value instead\");\n}","typeGuard":"fn clipboard_supported() -> bool {\n    cfg!(any(target_os = \"macos\", target_os = \"linux\"))\n}","tryCatchPattern":"match copy_to_clipboard(text) {\n    Err(e) if e.to_string().contains(\"clipboard not supported\") => {\n        println!(\"{text}\"); // graceful degradation: print instead of copy\n    }\n    Err(e) => return Err(e),\n    Ok(()) => {}\n}","preventionTips":["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"],"tags":["clipboard","platform","cross-platform","rust"],"backgroundTag":"unsupported-platform","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}