{"record":{"id":"02e71d560cf059c0","repo":"Hmbown/CodeWhale","slug":"primary-selection-unavailable","errorCode":null,"errorMessage":"PRIMARY selection unavailable","messagePattern":"PRIMARY selection unavailable","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/tui/src/tui/clipboard.rs","lineNumber":415,"sourceCode":"        #[cfg(test)]\n        {\n            self.primary_enabled\n        }\n        #[cfg(not(test))]\n        {\n            cfg!(all(target_os = \"linux\", not(target_env = \"ohos\")))\n        }\n    }\n\n    /// Automatic selection never writes CLIPBOARD or sends OSC 52. A remote\n    /// terminal without a forwarded display owns its own selection and paste.\n    pub(crate) fn write_primary_text(&mut self, text: &str) -> Result<()> {\n        if !self.uses_primary_selection()\n            || !self.terminal_context.permits_native_read()\n            || text.is_empty()\n            || text.len() > PRIMARY_MAX_BYTES\n        {\n            bail!(\"PRIMARY selection unavailable\");\n        }\n        #[cfg(test)]\n        {\n            if self.fail_text_writes {\n                bail!(\"test PRIMARY unavailable\");\n            }\n            self.primary_text = Some(text.to_string());\n            Ok(())\n        }\n        #[cfg(all(target_os = \"linux\", not(target_env = \"ohos\"), not(test)))]\n        {\n            self.primary_selection()?.write(text)\n        }\n        #[cfg(all(not(test), not(all(target_os = \"linux\", not(target_env = \"ohos\")))))]\n        {\n            bail!(\"PRIMARY selection unavailable\")\n        }\n    }","sourceCodeStart":397,"sourceCodeEnd":433,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/tui/clipboard.rs#L397-L433","documentation":"write_primary_text writes to the X11 PRIMARY selection (middle-click paste) through the clipboard transport. It refuses when any precondition fails: primary selection unsupported, native terminal reads not permitted, empty text, or text exceeding PRIMARY_MAX_BYTES — surfacing a single generic bail.","triggerScenarios":"Calling write_primary_text when uses_primary_selection() is false (no X11/PRIMARY support, e.g. Wayland-only or Windows/macOS), terminal_context.permits_native_read() is false (restricted terminal), text is empty, or text longer than PRIMARY_MAX_BYTES.","commonSituations":"Selecting text in a terminal over SSH or in a sandbox that blocks native reads; running on a platform without PRIMARY selection; selecting an enormous output region past the byte cap and trying to publish it as PRIMARY.","solutions":["Check supports: only call when the platform/terminal advertises PRIMARY selection (uses_primary_selection())","Trim or truncate the text under PRIMARY_MAX_BYTES before writing","Ensure the terminal context permits native reads (not SSH host clipboard, restricted mode)","Treat the error as 'primary not available' and fall back to the regular clipboard or do nothing"],"exampleFix":"// before\nclipboard.write_primary_text(selected)?;\n// after\nif clipboard.uses_primary_selection() && !selected.is_empty() && selected.len() <= PRIMARY_MAX_BYTES {\n    let _ = clipboard.write_primary_text(selected);\n}","handlingStrategy":"try-catch","validationCode":"if !clipboard.uses_primary_selection() || text.is_empty() || text.len() > PRIMARY_MAX_BYTES { /* skip or fallback */ }","typeGuard":null,"tryCatchPattern":"match clipboard.write_primary_text(text) { Err(_) => { /* PRIMARY unavailable: fall back to clipboard or ignore */ }, Ok(()) => {} }","preventionTips":["Gate writes on uses_primary_selection()","Truncate selection text under PRIMARY_MAX_BYTES","Don't rely on PRIMARY over SSH or restricted terminals","Treat PRIMARY as best-effort; never hard-fail on it"],"tags":["clipboard","x11","primary-selection","precondition"],"backgroundTag":"unsupported-operation","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}