mirror of
https://github.com/ytdl-org/youtube-dl
synced 2024-11-18 11:30:11 +09:00
[utils] Improve ExtractorError with msg IV and ie constructor param
This commit is contained in:
parent
58f15bb6c8
commit
eb93aaf702
@ -2412,26 +2412,28 @@ class YoutubeDLError(Exception):
|
|||||||
class ExtractorError(YoutubeDLError):
|
class ExtractorError(YoutubeDLError):
|
||||||
"""Error during info extraction."""
|
"""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).
|
""" 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 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):
|
self.msg = compat_str(msg)
|
||||||
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.traceback = tb
|
self.traceback = tb
|
||||||
self.exc_info = sys.exc_info() # preserve original exception
|
self.exc_info = sys.exc_info() # preserve original exception
|
||||||
self.cause = cause
|
self.cause = cause
|
||||||
self.video_id = video_id
|
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):
|
def format_traceback(self):
|
||||||
if self.traceback is None:
|
if self.traceback is None:
|
||||||
return None
|
return None
|
||||||
|
Loading…
Reference in New Issue
Block a user