Repository: alexpasmantier/television (language: rust)

Issue:
Crash when attempting to copy to clipboard
**Description**
I am using the `yash` shell under TTY1. When I press CTRL-Y in `tv`, it crashes.

**Example**
![Image](https://github.com/user-attachments/assets/28488ee5-3e74-4ae3-a1a7-73973bddef3d)

**Expected behavior**
It should gracefully fail, as I do not have a clipboard service.

**Actual behavior**
A crash occurs, as shown in above image.

**Environment**
 - OS: Linux
 - Rust version: n/a
 - Project version: 0.10.4

**Additional context**
non-graphical session



Discussion / hints:

Fix patch:
diff --git a/television/television.rs b/television/television.rs
index 73fd0eb..29e0e48 100644
--- a/television/television.rs
+++ b/television/television.rs
@@ -22,6 +22,7 @@ use rustc_hash::{FxBuildHasher, FxHashMap, FxHashSet};
 use serde::{Deserialize, Serialize};
 use std::collections::HashSet;
 use tokio::sync::mpsc::{Receiver, Sender, UnboundedSender};
+use tracing::error;
 
 #[derive(PartialEq, Copy, Clone, Hash, Eq, Debug, Serialize, Deserialize)]
 pub enum Mode {
@@ -480,15 +481,20 @@ impl Television {
     pub fn handle_copy_entry_to_clipboard(&mut self) {
         if self.mode == Mode::Channel {
             if let Some(entries) = self.get_selected_entries(None) {
-                let mut ctx = ClipboardContext::new().unwrap();
-                ctx.set_contents(
-                    entries
-                        .iter()
-                        .map(|e| e.name.clone())
-                        .collect::<Vec<_>>()
-                        .join(" "),
-                )
-                .unwrap();
+                if let Ok(mut ctx) = ClipboardContext::new() {
+                    ctx.set_contents(
+                        entries
+                            .iter()
+                            .map(|e| e.name.clone())
+                            .collect::<Vec<_>>()
+                            .join(" "),
+                    )
+                    .unwrap_or_else(|_| {
+                        error!("Could not copy to clipboard");
+                    });
+                } else {
+                    error!("Could not copy to clipboard");
+                }
             }
         }
     }


Test patch: