From 1151c4079a15939c981f3e30129b82dea1b1bc6d Mon Sep 17 00:00:00 2001 From: pukkandan Date: Thu, 19 Aug 2021 07:19:23 +0530 Subject: [extractor] Show video id in error messages if possible --- yt_dlp/utils.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'yt_dlp/utils.py') diff --git a/yt_dlp/utils.py b/yt_dlp/utils.py index c07a17099..61878b8d7 100644 --- a/yt_dlp/utils.py +++ b/yt_dlp/utils.py @@ -2399,25 +2399,27 @@ network_exceptions = tuple(network_exceptions) 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 yt-dlp. """ - if sys.exc_info()[0] in network_exceptions: 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 = msg self.traceback = tb - self.exc_info = sys.exc_info() # preserve original exception + self.expected = expected self.cause = cause self.video_id = video_id + self.ie = ie + self.exc_info = sys.exc_info() # preserve original exception + + super(ExtractorError, self).__init__(''.join(( + format_field(ie, template='[%s] '), + format_field(video_id, template='%s: '), + msg, + format_field(cause, template=' (caused by %r)'), + '' if expected else bug_reports_message()))) def format_traceback(self): if self.traceback is None: -- cgit v1.2.3