{"record":{"id":"e8b5e15c99c33bab","repo":"sigoden/aichat","slug":"no-clipboard-available","errorCode":null,"errorMessage":"No clipboard available","messagePattern":"No clipboard available","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/utils/clipboard.rs","lineNumber":43,"sourceCode":"    /// Attempts to set text to clipboard with OSC52 escape sequence\n    /// Works in many modern terminals, including over SSH.\n    fn set_text_osc52(text: &str) -> anyhow::Result<()> {\n        let encoded = STANDARD.encode(text);\n        let seq = format!(\"\\x1b]52;c;{encoded}\\x07\");\n        if let Err(e) = std::io::Write::write_all(&mut std::io::stdout(), seq.as_bytes()) {\n            return Err(anyhow::anyhow!(\"Failed to send OSC52 sequence\").context(e));\n        }\n        if let Err(e) = std::io::Write::flush(&mut std::io::stdout()) {\n            return Err(anyhow::anyhow!(\"Failed to flush OSC52 sequence\").context(e));\n        }\n        Ok(())\n    }\n}\n\n#[cfg(any(target_os = \"android\", target_os = \"emscripten\"))]\nmod internal {\n    pub fn set_text(_text: &str) -> anyhow::Result<()> {\n        Err(anyhow::anyhow!(\"No clipboard available\"))\n    }\n}\n\npub fn set_text(text: &str) -> anyhow::Result<()> {\n    internal::set_text(text).context(\"Failed to copy\")\n}\n","sourceCodeStart":25,"sourceCodeEnd":50,"githubUrl":"https://github.com/sigoden/aichat/blob/82976d349ad97ac9aae0655ad631dace5e2a6385/src/utils/clipboard.rs#L25-L50","documentation":"The public `set_text` delegates to a per-platform `internal::set_text`; on platforms the library does not support for clipboard access (`target_os = \"android\"` or `target_os = \"emscripten\"`), the stub unconditionally returns `Err(\"No clipboard available\")`, which the caller wraps with the context \"Failed to copy\". It signals that clipboard write is simply not implemented for the current target, not that the copy content was invalid.","triggerScenarios":"Calling `set_text(text)` while compiled for Android or Emscripten (the `#[cfg(any(target_os = \"android\", target_os = \"emscripten\"))]` branch is active).","commonSituations":"Building a CLI/TUI tool for mobile or WASM targets; running the app in an Android shell or browser-emscripten environment; cross-compiling for an unsupported platform and then invoking copy features.","solutions":["Check the target OS at runtime/compile time and skip or degrade clipboard features on Android/Emscripten.","Use a platform-specific clipboard mechanism on those targets (Android ClipboardManager, browser navigator.clipboard for WASM).","Catch this error and present a non-fatal message, allowing the user to copy manually.","If you own the build, feature-gate the clipboard call behind a capability check."],"exampleFix":"// before\nclipboard::set_text(&text).context(\"Failed to copy\")?;\n// after\n#[cfg(any(target_os = \"android\", target_os = \"emscripten\"))]\neprintln!(\"Clipboard is not supported on this platform; output printed instead\");\n#[cfg(not(any(target_os = \"android\", target_os = \"emscripten\")))]\nclipboard::set_text(&text).context(\"Failed to copy\")?;","handlingStrategy":"fallback","validationCode":"#[cfg(any(target_os = \"android\", target_os = \"emscripten\"))]\nconst CLIPBOARD_SUPPORTED: bool = false;\n#[cfg(not(any(target_os = \"android\", target_os = \"emscripten\")))]\nconst CLIPBOARD_SUPPORTED: bool = true;","typeGuard":"fn clipboard_supported() -> bool {\n    !cfg!(any(target_os = \"android\", target_os = \"emscripten\"))\n}","tryCatchPattern":"match set_text(text) {\n    Err(e) if e.to_string().contains(\"No clipboard available\") => {\n        println!(\"{text}\"); // let the user copy manually\n    }\n    other => other?,\n}","preventionTips":["Compile-time gate clipboard features on target OS with cfg!.","Provide a print-to-stdout fallback for unsupported targets.","Document platform support for clipboard features in the README.","Test WASM/mobile builds in CI so unsupported code paths surface early."],"tags":["clipboard","platform","android","emscripten"],"backgroundTag":"unsupported-platform","analyzedSha":"82976d349ad97ac9aae0655ad631dace5e2a6385","analyzedAt":"2026-09-09T18:33:06.139Z","contentChangedAt":"2026-09-09T18:33:06.139Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}