aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--crates/yt_dlp/src/error.rs27
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,
+ }
+ })
}
}