WOrking on revamping the loader exceptions again.

This commit is contained in:
Michael Lazar
2015-12-07 01:12:09 -08:00
parent 6fa431aec9
commit 3a117f42af

View File

@@ -12,10 +12,10 @@ import threading
from contextlib import contextmanager from contextlib import contextmanager
import six import six
from praw.errors import PRAWException import praw
from requests import RequestException import requests
from .exceptions import RTVError from . import exceptions
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
@@ -111,6 +111,13 @@ class LoadScreen(object):
>>> assert isinstance(terminal.loader.exception, KeyboardInterrupt) >>> assert isinstance(terminal.loader.exception, KeyboardInterrupt)
""" """
EXCEPTION_MESSAGES = [
# These ones are triggered by us, so they should always have a message
(exceptions.RTVError, '{0}'),
(praw.errors.PRAWException, '{0.__class__}'),
(requests.exceptions.RequestException, '{0.__class__}'),
]
def __init__(self, terminal): def __init__(self, terminal):
self.exception = None self.exception = None
@@ -180,19 +187,15 @@ class LoadScreen(object):
exc_name = type(e).__name__ exc_name = type(e).__name__
_logger.info('Loader caught: {0} - {1}'.format(exc_name, e)) _logger.info('Loader caught: {0} - {1}'.format(exc_name, e))
# Some exceptions we want to swallow and display a notification if isinstance(e, KeyboardInterrupt):
handled_exceptions = (RTVError, PRAWException, RequestException) # Don't need to print anything for this one, just swallow it
if isinstance(e, handled_exceptions):
# Pass the message straight through to the user
message = six.text_type(e).split('/n') if str(e) else exc_name
self._terminal.show_notification(message)
return True return True
elif isinstance(e, KeyboardInterrupt):
# Don't need to print anything for this one for e_type, message in self.EXCEPTION_MESSAGES:
return True # Some exceptions we want to swallow and display a notification
else: if isinstance(e, e_type):
# Allow the exception to re-raise self._terminal.show_notification(message.format(e))
return None return True
def animate(self, delay, interval, message, trail): def animate(self, delay, interval, message, trail):