diff options
author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2025-02-16 09:42:28 +0100 |
---|---|---|
committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2025-02-16 09:42:28 +0100 |
commit | c83dfe5268e2db39fe731b2d38387b76d9586057 (patch) | |
tree | 66806f9a11d867b0d72dc8224e802eb8626cab85 | |
parent | fix(crates/libmpv2/Mpv::command): Correctly escape arguments (diff) | |
download | yt-c83dfe5268e2db39fe731b2d38387b76d9586057.zip |
fix(crates/yt_dlp/error::PythonError): Add the python type as `kind`
-rw-r--r-- | crates/yt_dlp/src/error.rs | 27 |
1 files 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<pyo3::PyErr> }, - IoError { error: io::Error }, + ResponseParseError { + error: serde_json::error::Error, + }, + PythonError { + error: Box<pyo3::PyErr>, + 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<serde_json::error::Error> for YtDlpError { impl From<pyo3::PyErr> 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, + } + }) } } |