diff options
author | Philipp Hagemeister <phihag@phihag.de> | 2013-01-03 15:39:55 +0100 |
---|---|---|
committer | Philipp Hagemeister <phihag@phihag.de> | 2013-01-03 15:39:55 +0100 |
commit | 01951dda7a27d3bd2331f22ded5d33876cf1dad9 (patch) | |
tree | 2fad7a068fe58717130e2d2378e2ca40e492f90b /youtube_dl | |
parent | 6e3dba168bd9662186f0071caf249e4d0c52beff (diff) |
Make ExtractorError usable for other causes
Diffstat (limited to 'youtube_dl')
-rw-r--r-- | youtube_dl/FileDownloader.py | 7 | ||||
-rwxr-xr-x | youtube_dl/InfoExtractors.py | 2 | ||||
-rw-r--r-- | youtube_dl/utils.py | 10 |
3 files changed, 13 insertions, 6 deletions
diff --git a/youtube_dl/FileDownloader.py b/youtube_dl/FileDownloader.py index 756fc72ec..55afbdbed 100644 --- a/youtube_dl/FileDownloader.py +++ b/youtube_dl/FileDownloader.py @@ -216,12 +216,15 @@ class FileDownloader(object): Depending on if the downloader has been configured to ignore download errors or not, this method may throw an exception or not when errors are found, after printing the message. + + tb, if given, is additional traceback information. """ if message is not None: self.to_stderr(message) if self.params.get('verbose'): if tb is None: - tb = u''.join(traceback.format_list(traceback.extract_stack())) + tb_data = traceback.format_list(traceback.extract_stack()) + tb = u''.join(tb_data) self.to_stderr(tb) if not self.params.get('ignoreerrors', False): raise DownloadError(message) @@ -497,7 +500,7 @@ class FileDownloader(object): try: videos = ie.extract(url) except ExtractorError as de: # An error we somewhat expected - self.trouble(u'ERROR: ' + compat_str(de), compat_str(u''.join(traceback.format_tb(de.traceback)))) + self.trouble(u'ERROR: ' + compat_str(de), de.format_traceback()) break except Exception as e: if self.params.get('ignoreerrors', False): diff --git a/youtube_dl/InfoExtractors.py b/youtube_dl/InfoExtractors.py index 7bea26142..d040eec82 100755 --- a/youtube_dl/InfoExtractors.py +++ b/youtube_dl/InfoExtractors.py @@ -117,7 +117,7 @@ class InfoExtractor(object): except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err: if errnote is None: errnote = u'Unable to download webpage' - raise ExtractorError(u'%s: %s' % (errnote, compat_str(err))) + raise ExtractorError(u'%s: %s' % (errnote, compat_str(err)), sys.exc_info()[2]) class YoutubeIE(InfoExtractor): diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index 91e180326..8f856ee8c 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -8,6 +8,7 @@ import locale import os import re import sys +import traceback import zlib import email.utils import json @@ -414,12 +415,15 @@ def encodeFilename(s): class ExtractorError(Exception): """Error during info extraction.""" def __init__(self, msg, tb=None): - """ tb 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). """ super(ExtractorError, self).__init__(msg) - if tb is None: - tb = sys.exc_info()[2] self.traceback = tb + def format_traceback(self): + if self.traceback is None: + return None + return u''.join(traceback.format_tb(self.traceback)) + class DownloadError(Exception): """Download Error exception. |