From f894b396b3eee4310fe5f6f7202b32d22d293c4e Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Sat, 7 Nov 2026 14:46:03 +0100 Subject: refactor(yt_dlp/python_error): Add context to every `wrap_exc` call Otherwise it is hard to debug where the wrapped exception was thrown. --- crates/yt_dlp/src/options.rs | 48 ++++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 17 deletions(-) (limited to 'crates/yt_dlp/src/options.rs') diff --git a/crates/yt_dlp/src/options.rs b/crates/yt_dlp/src/options.rs index a87473d..e3373b2 100644 --- a/crates/yt_dlp/src/options.rs +++ b/crates/yt_dlp/src/options.rs @@ -145,17 +145,20 @@ signal.signal(signal.SIGINT, signal.SIG_DFL) { // Setup the progress hook if let Some(ph) = options.progress_hook { - opts.set_item(intern!(py, "progress_hooks"), vec![ph(py).wrap_exc(py)?]) - .wrap_exc(py)?; + opts.set_item( + intern!(py, "progress_hooks"), + vec![ph(py).wrap_exc(py, "not having context")?], + ) + .wrap_exc(py, "not having context")?; } // Setup the post_processor hook if let Some(ph) = options.post_processor_hook { opts.set_item( intern!(py, "postprocessor_hooks"), - vec![ph(py).wrap_exc(py)?], + vec![ph(py).wrap_exc(py, "not having context")?], ) - .wrap_exc(py)?; + .wrap_exc(py, "not having context")?; } } @@ -163,47 +166,58 @@ signal.signal(signal.SIGINT, signal.SIG_DFL) // Unconditionally set a logger. // Otherwise, yt_dlp will log to stderr. - let ytdl_logger = setup_logging(py, "yt_dlp").wrap_exc(py)?; + let ytdl_logger = setup_logging(py, "yt_dlp").wrap_exc(py, "not having context")?; opts.set_item(intern!(py, "logger"), ytdl_logger) - .wrap_exc(py)?; + .wrap_exc(py, "not having context")?; } let inner = { - let p_params = opts.into_bound_py_any(py).wrap_exc(py)?; - let p_auto_init = true.into_bound_py_any(py).wrap_exc(py)?; + let p_params = opts + .into_bound_py_any(py) + .wrap_exc(py, "not having context")?; + let p_auto_init = true + .into_bound_py_any(py) + .wrap_exc(py, "not having context")?; py.import(intern!(py, "yt_dlp.YoutubeDL")) - .wrap_exc(py)? + .wrap_exc(py, "not having context")? .getattr(intern!(py, "YoutubeDL")) - .wrap_exc(py)? + .wrap_exc(py, "not having context")? .call1( PyTuple::new( py, [ - p_params.into_bound_py_any(py).wrap_exc(py)?, - p_auto_init.into_bound_py_any(py).wrap_exc(py)?, + p_params + .into_bound_py_any(py) + .wrap_exc(py, "not having context")?, + p_auto_init + .into_bound_py_any(py) + .wrap_exc(py, "not having context")?, ], ) - .wrap_exc(py)?, + .wrap_exc(py, "not having context")?, ) - .wrap_exc(py)? + .wrap_exc(py, "not having context")? }; { // Setup the post processors let add_post_processor_fun = inner .getattr(intern!(py, "add_post_processor")) - .wrap_exc(py)?; + .wrap_exc(py, "not having context")?; for pp in options.post_processors { add_post_processor_fun .call( - (pp(py).wrap_exc(py)?.into_bound_py_any(py).wrap_exc(py)?,), + (pp(py) + .wrap_exc(py, "not having context")? + .into_bound_py_any(py) + .wrap_exc(py, "not having context")?,), // "when" can take any value in yt_dlp.utils.POSTPROCESS_WHEN py_kw_args!(py => when = "pre_process"), ) - .wrap_exc(py)?; + .wrap_exc(py, "not having context")?; } } -- cgit v1.3.1