mirror of https://github.com/yt-dlp/yt-dlp.git
[utils] Make `ExtractorError` mutable
This commit is contained in:
parent
71eb82d1b2
commit
9bcfe33be7
|
@ -692,16 +692,10 @@ class InfoExtractor:
|
|||
except UnsupportedError:
|
||||
raise
|
||||
except ExtractorError as e:
|
||||
kwargs = {
|
||||
'video_id': e.video_id or self.get_temp_id(url),
|
||||
'ie': self.IE_NAME,
|
||||
'tb': e.traceback or sys.exc_info()[2],
|
||||
'expected': e.expected,
|
||||
'cause': e.cause
|
||||
}
|
||||
if hasattr(e, 'countries'):
|
||||
kwargs['countries'] = e.countries
|
||||
raise type(e)(e.orig_msg, **kwargs)
|
||||
e.video_id = e.video_id or self.get_temp_id(url),
|
||||
e.ie = e.ie or self.IE_NAME,
|
||||
e.traceback = e.traceback or sys.exc_info()[2]
|
||||
raise
|
||||
except http.client.IncompleteRead as e:
|
||||
raise ExtractorError('A network error has occurred.', cause=e, expected=True, video_id=self.get_temp_id(url))
|
||||
except (KeyError, StopIteration) as e:
|
||||
|
|
|
@ -1095,13 +1095,16 @@ class ExtractorError(YoutubeDLError):
|
|||
self.exc_info = sys.exc_info() # preserve original exception
|
||||
if isinstance(self.exc_info[1], ExtractorError):
|
||||
self.exc_info = self.exc_info[1].exc_info
|
||||
super().__init__(self.__msg)
|
||||
|
||||
super().__init__(''.join((
|
||||
format_field(ie, None, '[%s] '),
|
||||
format_field(video_id, None, '%s: '),
|
||||
msg,
|
||||
format_field(cause, None, ' (caused by %r)'),
|
||||
'' if expected else bug_reports_message())))
|
||||
@property
|
||||
def __msg(self):
|
||||
return ''.join((
|
||||
format_field(self.ie, None, '[%s] '),
|
||||
format_field(self.video_id, None, '%s: '),
|
||||
self.orig_msg,
|
||||
format_field(self.cause, None, ' (caused by %r)'),
|
||||
'' if self.expected else bug_reports_message()))
|
||||
|
||||
def format_traceback(self):
|
||||
return join_nonempty(
|
||||
|
@ -1109,6 +1112,12 @@ class ExtractorError(YoutubeDLError):
|
|||
self.cause and ''.join(traceback.format_exception(None, self.cause, self.cause.__traceback__)[1:]),
|
||||
delim='\n') or None
|
||||
|
||||
def __setattr__(self, name, value):
|
||||
super().__setattr__(name, value)
|
||||
if getattr(self, 'msg', None) and name not in ('msg', 'args'):
|
||||
self.msg = self.__msg or type(self).__name__
|
||||
self.args = (self.msg, ) # Cannot be property
|
||||
|
||||
|
||||
class UnsupportedError(ExtractorError):
|
||||
def __init__(self, url):
|
||||
|
|
Loading…
Reference in New Issue