aboutsummaryrefslogtreecommitdiffstats
path: root/crates/yt_dlp/src/lib.rs
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2026-11-07 14:46:03 +0100
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2026-11-07 14:46:03 +0100
commitf894b396b3eee4310fe5f6f7202b32d22d293c4e (patch)
tree51cc15b24da4b94ed5f0776d9d5305c009cba17e /crates/yt_dlp/src/lib.rs
parentfix(yt/db/get/txn_log): Order by `ROWID` instead of `timestamp` (diff)
downloadyt-f894b396b3eee4310fe5f6f7202b32d22d293c4e.zip
refactor(yt_dlp/python_error): Add context to every `wrap_exc` call
Otherwise it is hard to debug where the wrapped exception was thrown.
Diffstat (limited to 'crates/yt_dlp/src/lib.rs')
-rw-r--r--crates/yt_dlp/src/lib.rs42
1 files changed, 24 insertions, 18 deletions
diff --git a/crates/yt_dlp/src/lib.rs b/crates/yt_dlp/src/lib.rs
index abe766d..22c9185 100644
--- a/crates/yt_dlp/src/lib.rs
+++ b/crates/yt_dlp/src/lib.rs
@@ -93,7 +93,7 @@ macro_rules! py_kw_args {
let dict = PyDict::new($py);
$(
- dict.set_item(stringify!($kw_arg_name), $kw_arg_val).wrap_exc($py)?;
+ dict.set_item(stringify!($kw_arg_name), $kw_arg_val).wrap_exc($py, "constructing python kw args")?;
)*
Some(dict)
@@ -118,13 +118,13 @@ impl YoutubeDL {
Python::attach(|py| {
let yt_dlp = py
.import(intern!(py, "yt_dlp"))
- .wrap_exc(py)?
+ .wrap_exc(py, "importing yt_dlp")?
.getattr(intern!(py, "version"))
- .wrap_exc(py)?
+ .wrap_exc(py, "accessing 'version'")?
.getattr(intern!(py, "__version__"))
- .wrap_exc(py)?
+ .wrap_exc(py, "accessing '__version__'")?
.extract()
- .wrap_exc(py)?;
+ .wrap_exc(py, "extracting version as str")?;
let python = py.version();
@@ -194,14 +194,14 @@ impl YoutubeDL {
.inner
.bind(py)
.getattr(intern!(py, "extract_info"))
- .wrap_exc(py)?;
+ .wrap_exc(py, "extracting extract_info as function")?;
let result = inner
.call(
(url.to_string(),),
py_kw_args!(py => download = download, process = process),
)
- .wrap_exc(py)?
+ .wrap_exc(py, "calling extract_info")?
.cast_into::<PyDict>()
.expect("This is a dict");
@@ -218,14 +218,16 @@ impl YoutubeDL {
let mut out = vec![];
for output in generator {
- out.push(output.wrap_exc(py)?);
+ out.push(output.wrap_exc(py, "processing playlist item")?);
if out.len() == max_backlog {
break;
}
}
- result.set_item(intern!(py, "entries"), out).wrap_exc(py)?;
+ result
+ .set_item(intern!(py, "entries"), out)
+ .wrap_exc(py, "setting playlist 'entries'")?;
} else {
// Probably some sort of paged list (`OnDemand` or otherwise)
let max_backlog = json_try_get!(self.options, "playlistend", as_u64)
@@ -233,15 +235,17 @@ impl YoutubeDL {
usize::try_from(playlistend).expect("Should work")
});
- let next = generator.getattr(intern!(py, "getslice")).wrap_exc(py)?;
+ let next = generator
+ .getattr(intern!(py, "getslice"))
+ .wrap_exc(py, "getting 'getslice' attribute")?;
let output = next
.call((), py_kw_args!(py => start = 0, end = max_backlog))
- .wrap_exc(py)?;
+ .wrap_exc(py, "calling 'getslice'")?;
result
.set_item(intern!(py, "entries"), output)
- .wrap_exc(py)?;
+ .wrap_exc(py, "setting 'entries' key")?;
}
}
@@ -274,14 +278,14 @@ impl YoutubeDL {
.inner
.bind(py)
.getattr(intern!(py, "process_ie_result"))
- .wrap_exc(py)?;
+ .wrap_exc(py, "getting process_ie_result")?;
let result = inner
.call(
(json_loads(ie_result, py),),
py_kw_args!(py => download = download),
)
- .wrap_exc(py)?
+ .wrap_exc(py, "calling process_ie_result")?
.cast_into::<PyDict>()
.expect("This is a dict");
@@ -303,9 +307,9 @@ impl YoutubeDL {
.inner
.bind(py)
.getattr(intern!(py, "close"))
- .wrap_exc(py)?;
+ .wrap_exc(py, "getting 'close'")?;
- inner.call0().wrap_exc(py)?;
+ inner.call0().wrap_exc(py, "calling 'close'")?;
Ok(())
})
@@ -320,9 +324,11 @@ impl YoutubeDL {
.inner
.bind(py)
.getattr(intern!(py, "sanitize_info"))
- .wrap_exc(py)?;
+ .wrap_exc(py, "getting 'sanitize_info'")?;
- let value = sanitize.call((info,), None).wrap_exc(py)?;
+ let value = sanitize
+ .call((info,), None)
+ .wrap_exc(py, "calling sanitize info")?;
let result = value.cast::<PyDict>().expect("This should stay a dict");