{"record":{"id":"a938c142a7cafee6","repo":"Hmbown/CodeWhale","slug":"selection-is-too-large-for-osc-52-clipboard-fallba","errorCode":null,"errorMessage":"selection is too large for OSC 52 clipboard fallback","messagePattern":"selection is too large for OSC 52 clipboard fallback","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/tui/clipboard.rs","lineNumber":631,"sourceCode":"            if write_text_with_pbcopy(text).is_ok() {\n                return Ok(());\n            }\n\n            #[cfg(target_os = \"windows\")]\n            if write_text_with_set_clipboard(text).is_ok() {\n                return Ok(());\n            }\n\n            self.enqueue_terminal_write(text)\n                .map_err(|err| anyhow::anyhow!(\"Clipboard unavailable: {err}\"))\n        }\n    }\n\n    #[cfg(not(test))]\n    fn enqueue_terminal_write(&mut self, text: &str) -> Result<()> {\n        if !self.terminal_context.in_tmux {\n            if text.len() > OSC52_MAX_BYTES {\n                bail!(\"selection is too large for OSC 52 clipboard fallback\");\n            }\n            if !io::stdout().is_terminal() {\n                bail!(\"OSC 52 clipboard fallback requires a terminal\");\n            }\n        }\n\n        if self.terminal_writer.is_none() {\n            self.terminal_writer = Some(TerminalClipboardWriter::spawn()?);\n        }\n        self.terminal_writer\n            .as_ref()\n            .expect(\"terminal clipboard writer initialized\")\n            .enqueue(text, self.terminal_context.in_tmux)\n    }\n\n    /// Return one completed background terminal clipboard write, if available.\n    ///\n    /// Successes are intentionally quiet because callers already show their","sourceCodeStart":613,"sourceCodeEnd":649,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/tui/clipboard.rs#L613-L649","documentation":"When not running inside tmux, `enqueue_terminal_write` writes the clipboard via an OSC 52 escape sequence emitted to stdout. OSC 52 payloads are base64-encoded and terminal emulators cap how much they accept, so selections larger than `OSC52_MAX_BYTES` are rejected up front with this error rather than being silently truncated or dropped by the terminal.","triggerScenarios":"Calling `write_text` (which routes to `enqueue_terminal_write`) with a selection whose byte length exceeds `OSC52_MAX_BYTES`, while `terminal_context.in_tmux` is false.","commonSituations":"Yanking a very large block of text (logs, minified JSON, big code files) to the clipboard in a plain terminal without tmux; piping Codewhale output where stdout is large.","solutions":["Reduce the amount of text being copied to the clipboard","Run inside tmux, where the OSC 52 size gate is bypassed and tmux's own load-buffer path is used","Use a system clipboard helper (wl-copy/xclip/pbcopy) path instead of the terminal fallback"],"exampleFix":"// before\nclipboard.write_text(&huge_output)?;\n// after\nif huge_output.len() > OSC52_MAX_BYTES {\n    clipboard.write_text(&huge_output[..OSC52_MAX_BYTES])?; // or use a system helper\n} else {\n    clipboard.write_text(&huge_output)?;\n}","handlingStrategy":"validation","validationCode":"if !in_tmux && text.len() > OSC52_MAX_BYTES {\n    // truncate, chunk, or route to a system clipboard helper instead\n}","typeGuard":"fn fits_osc52(text: &str, in_tmux: bool) -> bool {\n    in_tmux || text.len() <= OSC52_MAX_BYTES\n}","tryCatchPattern":"match clipboard.write_text(text) {\n    Err(e) if e.to_string().contains(\"too large for OSC 52\") => {\n        write_with_system_helper(text)?;\n    }\n    other => other?,\n}","preventionTips":["Check `text.len()` against `OSC52_MAX_BYTES` before copying large selections","Prefer wl-copy/xclip/pbcopy for payloads beyond a few KiB","Warn users in the UI when a copy exceeds the OSC 52 limit"],"tags":["clipboard","osc52","size-limit","terminal"],"backgroundTag":"payload-too-large","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"}