From 55beaf1281e7b522e0526b2aa2bf74d15f6c1263 Mon Sep 17 00:00:00 2001 From: Alexey Date: Tue, 2 May 2017 19:46:52 +0300 Subject: [PATCH] Inproved PolystorageError exceptions in log (#3732) --- socorro/external/crashstorage_base.py | 7 ++++++- socorro/unittest/external/test_crashstorage_base.py | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/socorro/external/crashstorage_base.py b/socorro/external/crashstorage_base.py index fb4921f856..d9da2fae0d 100644 --- a/socorro/external/crashstorage_base.py +++ b/socorro/external/crashstorage_base.py @@ -457,7 +457,7 @@ class PolyStorageError(Exception, collections.MutableSequence): message - an optional over all error message """ def __init__(self, message=''): - super(PolyStorageError, self).__init__(self, message) + super(PolyStorageError, self).__init__(message) self.exceptions = [] # the collection def gather_current_exception(self): @@ -494,6 +494,11 @@ def __setitem__(self, index, value): this method is required by the MutableSequence abstract base class""" self.exceptions.__setitem__(index, value) + def __str__(self): + return '%s %s' % (self.message, + ','.join(repr(e[1]).encode('ascii', 'ignore') + for e in self.exceptions)) + #============================================================================== class PolyCrashStorage(CrashStorageBase): diff --git a/socorro/unittest/external/test_crashstorage_base.py b/socorro/unittest/external/test_crashstorage_base.py index 12d3c55e16..6adac122fe 100644 --- a/socorro/unittest/external/test_crashstorage_base.py +++ b/socorro/unittest/external/test_crashstorage_base.py @@ -262,6 +262,11 @@ def test_polyerror(self): [eq_(a[0], b) for a, b in zip(x, types)] ok_(1 not in x) ok_(str(x[0][1]), 'dwight') + ok_( + all(sample in str(x) for sample in + ['hell', 'NameError', 'KeyError', 'AttributeError']), + x + ) x[0] = x[1] eq_(x[0], x[1])