aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--crates/yt_dlp/src/lib.rs36
1 files changed, 27 insertions, 9 deletions
diff --git a/crates/yt_dlp/src/lib.rs b/crates/yt_dlp/src/lib.rs
index dd42fc6..1f859fe 100644
--- a/crates/yt_dlp/src/lib.rs
+++ b/crates/yt_dlp/src/lib.rs
@@ -22,19 +22,37 @@ pub mod progress_hook;
#[macro_export]
macro_rules! json_get {
- ($value:expr, $name:literal, $into:ident) => {
- $crate::json_cast!($value.get($name).expect("Should exist"), $into)
- };
+ ($value:expr, $name:literal, $into:ident) => {{
+ match $value.get($name) {
+ Some(val) => $crate::json_cast!(val, $into),
+ None => panic!(
+ concat!(
+ "Expected '",
+ $name,
+ "' to be a key for the'",
+ stringify!($value),
+ "' object: {:#?}"
+ ),
+ $value
+ ),
+ }
+ }};
}
#[macro_export]
macro_rules! json_cast {
- ($value:expr, $into:ident) => {
- $value.$into().expect(concat!(
- "Should be able to cast value into ",
- stringify!($into)
- ))
- };
+ ($value:expr, $into:ident) => {{
+ match $value.$into() {
+ Some(result) => result,
+ None => panic!(
+ concat!(
+ "Expected to be able to cast value ({:#?}) ",
+ stringify!($into)
+ ),
+ $value
+ ),
+ }
+ }};
}
/// The core of the `yt_dlp` interface.