From c83dfe5268e2db39fe731b2d38387b76d9586057 Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Sun, 16 Feb 2025 09:42:28 +0100 Subject: fix(crates/yt_dlp/error::PythonError): Add the python type as `kind` --- crates/yt_dlp/src/error.rs | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/crates/yt_dlp/src/error.rs b/crates/yt_dlp/src/error.rs index 4327f0d..489abd3 100644 --- a/crates/yt_dlp/src/error.rs +++ b/crates/yt_dlp/src/error.rs @@ -1,11 +1,20 @@ use std::{fmt::Display, io}; +use pyo3::Python; + #[derive(Debug)] #[allow(clippy::module_name_repetitions)] pub enum YtDlpError { - ResponseParseError { error: serde_json::error::Error }, - PythonError { error: Box }, - IoError { error: io::Error }, + ResponseParseError { + error: serde_json::error::Error, + }, + PythonError { + error: Box, + kind: String, + }, + IoError { + error: io::Error, + }, } impl std::error::Error for YtDlpError {} @@ -18,7 +27,7 @@ impl Display for YtDlpError { include_str!("./python_json_decode_failed.error_msg"), error ), - YtDlpError::PythonError { error } => write!(f, "Python error: {error}"), + YtDlpError::PythonError { error, kind: _ } => write!(f, "Python error: {error}"), YtDlpError::IoError { error } => write!(f, "Io error: {error}"), } } @@ -32,9 +41,13 @@ impl From for YtDlpError { impl From for YtDlpError { fn from(value: pyo3::PyErr) -> Self { - Self::PythonError { - error: Box::new(value), - } + Python::with_gil(|py| { + let kind = value.get_type(py).to_string(); + Self::PythonError { + error: Box::new(value), + kind, + } + }) } } -- cgit 1.4.1