stop the error propogating (bug 734422)
This commit is contained in:
Родитель
5c0cc821f0
Коммит
8e78ea2744
|
@ -39,6 +39,26 @@ cfg = {
|
|||
}
|
||||
|
||||
|
||||
class TestUnicodeLog(amo.tests.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
dictconfig.dictConfig(cfg)
|
||||
self.log = logging.getLogger('test.lib.misc.logging')
|
||||
|
||||
@patch('logging.Handler.format')
|
||||
@patch('socket._socketobject.sendto')
|
||||
def test_unicode_error(self, sendto, _format):
|
||||
def blowup(*args, **kwargs):
|
||||
if args[0].__dict__['msg'] == 'blowup':
|
||||
raise UnicodeDecodeError('ascii', 'bytes', 0, 1, 'ouch')
|
||||
return args[0].__dict__['msg']
|
||||
_format.side_effect = blowup
|
||||
self.log.error('blowup')
|
||||
self.log.error('dont blowup')
|
||||
assert 'A unicode error occured' in sendto.call_args_list[0][0][0]
|
||||
assert 'dont' in sendto.call_args_list[1][0][0]
|
||||
|
||||
|
||||
class TestErrorLog(amo.tests.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
|
|
|
@ -8,7 +8,15 @@ class UnicodeHandler(logging.handlers.SysLogHandler):
|
|||
if hasattr(self, '_fmt') and not isinstance(self._fmt, unicode):
|
||||
# Ensure that the formatter does not coerce to str. bug 734422.
|
||||
self._fmt = unicode(self._fmt)
|
||||
msg = self.format(record) + '\000'
|
||||
|
||||
try:
|
||||
msg = self.format(record) + '\000'
|
||||
except UnicodeDecodeError:
|
||||
# At the very least, an error in logging should never propogate
|
||||
# up to the site and give errors for our users. This should still
|
||||
# be fixed.
|
||||
msg = u'A unicode error occured in logging \000'
|
||||
|
||||
prio = '<%d>' % self.encodePriority(self.facility,
|
||||
self.mapPriority(record.levelname))
|
||||
if type(msg) is unicode:
|
||||
|
|
Загрузка…
Ссылка в новой задаче