Merge pull request #190 from facetoe/master

Truncate long error messages.
This commit is contained in:
enkore 2015-04-03 15:22:23 +02:00
commit e5c128ea39
2 changed files with 10 additions and 3 deletions

View File

@ -75,10 +75,18 @@ class ExceptionWrapper(Wrapper):
sys.stderr.flush() sys.stderr.flush()
if hasattr(self.workload, "output"): if hasattr(self.workload, "output"):
self.workload.output = { self.workload.output = {
"full_text": "{}: {}".format(self.workload.__class__.__name__, sys.exc_info()[1]), "full_text": "{}: {}".format(self.workload.__class__.__name__,
self.format_error(str(sys.exc_info()[1]))),
"color": "#FF0000", "color": "#FF0000",
} }
def format_error(self, exception_message):
if hasattr(self.workload, 'max_error_len'):
error_len = self.workload.max_error_len
return exception_message[:error_len] + '...' if len(exception_message) > error_len else exception_message
else:
return exception_message
class WorkloadWrapper(Wrapper): class WorkloadWrapper(Wrapper):
time = 0.0 time = 0.0

View File

@ -16,6 +16,7 @@ class Github(IntervalModule):
* `{unread_count}` - number of unread notifications, empty if 0 * `{unread_count}` - number of unread notifications, empty if 0
""" """
max_error_len = 50
unread_marker = "" unread_marker = ""
unread = '' unread = ''
color = '#78EAF2' color = '#78EAF2'
@ -49,8 +50,6 @@ class Github(IntervalModule):
# Bad credentials # Bad credentials
if isinstance(data, dict): if isinstance(data, dict):
err_msg = data['message'] err_msg = data['message']
if len(err_msg) > 10:
err_msg = "%s%s" % (err_msg[:10], '...')
raise ConfigError(err_msg) raise ConfigError(err_msg)
unread = len(data) unread = len(data)