[FIX] handle correctly the convertion of exceptions to unicode

lp bug: https://launchpad.net/bugs/314292 fixed

bzr revid: christophe@tinyerp.com-20090107184427-jnpi8sc14qduspwe
This commit is contained in:
Christophe Simonis 2009-01-07 19:44:27 +01:00
parent 6c360b6d59
commit 195fc4a475
2 changed files with 16 additions and 2 deletions

View File

@ -160,6 +160,9 @@ class Logger(object):
level_method = getattr(log, level)
if isinstance(msg, Exception):
msg = tools.exception_to_unicode(msg)
result = tools.ustr(msg).strip().split('\n')
if len(result)>1:
for idx, s in enumerate(result):
@ -238,7 +241,7 @@ class GenericXMLRPCRequestHandler(OpenERPDispatcher):
service_name = self.path.split("/")[-1]
return self.dispatch(service_name, method, params)
except OpenERPDispatcherException, e:
raise xmlrpclib.Fault(str(e.exception), e.traceback)
raise xmlrpclib.Fault(tools.exception_to_unicode(e.exception), e.traceback)
class SSLSocket(object):
def __init__(self, socket):
@ -353,7 +356,7 @@ class TinySocketClientThread(threading.Thread, OpenERPDispatcher):
result = self.dispatch(msg[0], msg[1], msg[2:])
ts.mysend(result)
except OpenERPDispatcherException, e:
new_e = Exception(tools.ustr(e.exception)) # avoid problems of pickeling
new_e = Exception(tools.exception_to_unicode(e.exception)) # avoid problems of pickeling
ts.mysend(new_e, exception=True, traceback=e.traceback)
self.sock.close()

View File

@ -679,6 +679,17 @@ def ustr(value):
return unicode(value, 'utf-8')
def exception_to_unicode(e):
if hasattr(e, 'message'):
return ustr(e.message)
if hasattr(e, 'args'):
return "\n".join((ustr(a) for a in e.args))
try:
return ustr(e)
except:
return u"Unknow message"
# to be compatible with python 2.4
import __builtin__
if not hasattr(__builtin__, 'all'):