Enable log messages to handle exceptions containing unicode

Currently the format string is a normal string, which in
py2x is not unicode.  When the unicode exception information is
used to replace the %s, str() is called on it, but because
it is unicode str() fails.  Making the format string unicode
fixes this.  For the error log this is done by making it
translatable and for the debug message by explicity making
it unicode.

The exception will contain unicode when the exception being
returned by the other project is either translated to a
language using unicode characters or when lazy translation
is enabled and a gettextutils.Message instance is returned.

Change-Id: I1706f5eb9dfbee434f8882b03dad4674d955c370
Closes-Bug: #1310397
This commit is contained in:
James Carey 2014-04-20 20:28:15 +00:00
parent 06ab616d8f
commit 8e38175938
1 changed files with 3 additions and 2 deletions

View File

@ -32,6 +32,7 @@ import six
from oslo.messaging import _utils as utils
from oslo.messaging import localcontext
from oslo.messaging.openstack.common.gettextutils import _ # noqa
from oslo.messaging import serializer as msg_serializer
from oslo.messaging import server as msg_server
from oslo.messaging import target as msg_target
@ -132,13 +133,13 @@ class RPCDispatcher(object):
incoming.reply(self._dispatch(incoming.ctxt,
incoming.message))
except ExpectedException as e:
LOG.debug('Expected exception during message handling (%s)' %
LOG.debug(u'Expected exception during message handling (%s)' %
e.exc_info[1])
incoming.reply(failure=e.exc_info, log_failure=False)
except Exception as e:
# sys.exc_info() is deleted by LOG.exception().
exc_info = sys.exc_info()
LOG.error('Exception during message handling: %s', e,
LOG.error(_('Exception during message handling: %s'), e,
exc_info=exc_info)
incoming.reply(failure=exc_info)
# NOTE(dhellmann): Remove circular object reference