about summary refs log tree commit diff
diff options
context:
space:
mode:
authordirkf <fieldhouse@gmx.net>2022-01-26 14:54:43 +0000
committerdirkf <fieldhouse@gmx.net>2022-01-27 03:14:43 +0000
commit2f6a844faf0d115d71c541a008b3c8d2cc92ef28 (patch)
tree1e32a18a751377a8992be2ac69a6d9c471e75678
parent7d1059d6b8c817cc37d7598c7372ba832e6b55e2 (diff)
downloadyoutube-dl-2f6a844faf0d115d71c541a008b3c8d2cc92ef28.tar.gz
youtube-dl-2f6a844faf0d115d71c541a008b3c8d2cc92ef28.tar.xz
youtube-dl-2f6a844faf0d115d71c541a008b3c8d2cc92ef28.zip
Improve ExtractorError with msg IV and ie constructor param
-rw-r--r--youtube_dl/utils.py24
1 files changed, 13 insertions, 11 deletions
diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py
index 0bc6be509..3c8b748b4 100644
--- a/youtube_dl/utils.py
+++ b/youtube_dl/utils.py
@@ -2348,26 +2348,28 @@ class YoutubeDLError(Exception):
 class ExtractorError(YoutubeDLError):
     """Error during info extraction."""
 
-    def __init__(self, msg, tb=None, expected=False, cause=None, video_id=None):
+    def __init__(self, msg, tb=None, expected=False, cause=None, video_id=None, ie=None):
         """ tb, if given, is the original traceback (so that it can be printed out).
         If expected is set, this is a normal error message and most likely not a bug in youtube-dl.
         """
 
-        if sys.exc_info()[0] in (compat_urllib_error.URLError, socket.timeout, UnavailableVideoError):
-            expected = True
-        if video_id is not None:
-            msg = video_id + ': ' + msg
-        if cause:
-            msg += ' (caused by %r)' % cause
-        if not expected:
-            msg += bug_reports_message()
-        super(ExtractorError, self).__init__(msg)
-
+        self.msg = compat_str(msg)
         self.traceback = tb
         self.exc_info = sys.exc_info()  # preserve original exception
         self.cause = cause
         self.video_id = video_id
 
+        expected = expected or (
+            self.exc_info[0] in (compat_urllib_error.URLError, socket.timeout, UnavailableVideoError))
+        msg = ''.join((
+            '[%s] ' % ie if ie is not None else '',
+            video_id + ': ' if video_id is not None else '',
+            self.msg or 'Extractor error',
+            (' (caused by %r)' % (cause, )) if cause else '',
+            bug_reports_message() if not expected else '',
+        ))
+        super(ExtractorError, self).__init__(msg)
+
     def format_traceback(self):
         if self.traceback is None:
             return None