Repository: dathere/qsv (language: rust)

Issue:
Handle `.unwrap()` in `qsv clipboard`
I wasn't expecting either `qsv clipboard` or `qsv prompt` to work in an online Jupyter Lab and it turns out as expected, but got a panic for the error:

![image](https://github.com/user-attachments/assets/cd1717a9-0f88-41ce-a02b-eef48c48d3d1)

https://github.com/jqnatividad/qsv/blob/640a32c958338694dff90aff5c09d05ed98d66e2/src/cmd/clipboard.rs#L42

- qsv v0.129.0
- Ubuntu
- Jupyter Lab (https://100.dathere.com/lessons/0)


Discussion / hints:

Fix patch:
diff --git a/src/cmd/clipboard.rs b/src/cmd/clipboard.rs
index e4fda0352..2539c425c 100644
--- a/src/cmd/clipboard.rs
+++ b/src/cmd/clipboard.rs
@@ -29,7 +29,7 @@ use std::io::Read;
 use arboard::Clipboard;
 use serde::Deserialize;
 
-use crate::{util, CliResult};
+use crate::{util, CliError, CliResult};
 
 #[allow(dead_code)]
 #[derive(Deserialize)]
@@ -37,9 +37,41 @@ struct Args {
     flag_save: bool,
 }
 
+impl From<arboard::Error> for CliError {
+    fn from(err: arboard::Error) -> Self {
+        match err {
+            arboard::Error::ClipboardNotSupported => CliError::Other(
+                "The clipboard may not be supported for the current environment.".to_string(),
+            ),
+            arboard::Error::ConversionFailure => CliError::Other(
+                "The content that was about the be transferred to/from the clipboard could not be \
+                 converted to the appropriate format."
+                    .to_string(),
+            ),
+            arboard::Error::ClipboardOccupied => CliError::Other(
+                "The clipboard was unaccessible when attempting to access/use it. It may have \
+                 been held by another process/thread."
+                    .to_string(),
+            ),
+            arboard::Error::ContentNotAvailable => CliError::Other(
+                "The clipboard contents were not available in the requested format. This could \
+                 either be due to the clipboard being empty or the clipboard contents having an \
+                 incompatible format to the requested one."
+                    .to_string(),
+            ),
+            arboard::Error::Unknown { description: _ } => CliError::Other(
+                "An unknown error occurred while attempting to use the clipboard.".to_string(),
+            ),
+            _ => CliError::Other(
+                "An unexpected error occurred while using the clipboard.".to_string(),
+            ),
+        }
+    }
+}
+
 pub fn run(argv: &[&str]) -> CliResult<()> {
     let args: Args = util::get_args(USAGE, argv)?;
-    let mut clipboard = Clipboard::new().unwrap();
+    let mut clipboard = Clipboard::new()?;
     if args.flag_save {
         let mut buffer = String::new();
         std::io::stdin().read_to_string(&mut buffer)?;


Test patch: