aboutsummaryrefslogtreecommitdiffstats
path: root/crates/yt_dlp/src/error.rs
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-02-14 16:11:49 +0100
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-02-14 16:13:17 +0100
commit4d1b8136bb23d009ee04d863780225ad9d9f9eed (patch)
tree636f197771692086b734144a7a93d1748907579e /crates/yt_dlp/src/error.rs
parentfix(crates/yt_dlp): Avoid printing the file extension in the progress display (diff)
downloadyt-4d1b8136bb23d009ee04d863780225ad9d9f9eed.zip
fix(crates/yt_dlp): Actually return errors instead of panicing
Diffstat (limited to 'crates/yt_dlp/src/error.rs')
-rw-r--r--crates/yt_dlp/src/error.rs45
1 files changed, 45 insertions, 0 deletions
diff --git a/crates/yt_dlp/src/error.rs b/crates/yt_dlp/src/error.rs
new file mode 100644
index 0000000..4327f0d
--- /dev/null
+++ b/crates/yt_dlp/src/error.rs
@@ -0,0 +1,45 @@
+use std::{fmt::Display, io};
+
+#[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 },
+}
+
+impl std::error::Error for YtDlpError {}
+
+impl Display for YtDlpError {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ match self {
+ YtDlpError::ResponseParseError { error } => write!(
+ f,
+ include_str!("./python_json_decode_failed.error_msg"),
+ error
+ ),
+ YtDlpError::PythonError { error } => write!(f, "Python error: {error}"),
+ YtDlpError::IoError { error } => write!(f, "Io error: {error}"),
+ }
+ }
+}
+
+impl From<serde_json::error::Error> for YtDlpError {
+ fn from(value: serde_json::error::Error) -> Self {
+ Self::ResponseParseError { error: value }
+ }
+}
+
+impl From<pyo3::PyErr> for YtDlpError {
+ fn from(value: pyo3::PyErr) -> Self {
+ Self::PythonError {
+ error: Box::new(value),
+ }
+ }
+}
+
+impl From<io::Error> for YtDlpError {
+ fn from(value: io::Error) -> Self {
+ Self::IoError { error: value }
+ }
+}