From 54e3189fb6edf79e57ffa51f16ca1f84522e86a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 17 Jan 2012 13:54:08 +0100 Subject: [PATCH] Keep traceback as str as we don't know the encoding issue2302 review225001 --- trytond/convert.py | 5 ++--- trytond/ir/cron.py | 3 +-- trytond/model/modelstorage.py | 3 +-- trytond/protocols/dispatcher.py | 11 ++++------- trytond/protocols/jsonrpc.py | 8 +------- trytond/protocols/webdav.py | 5 ++--- trytond/protocols/xmlrpc.py | 8 +------- 7 files changed, 12 insertions(+), 31 deletions(-) diff --git a/trytond/convert.py b/trytond/convert.py index 62452caba7..7953e79ad1 100644 --- a/trytond/convert.py +++ b/trytond/convert.py @@ -983,8 +983,7 @@ def post_import(pool, module, to_delete): cursor.commit() except Exception: cursor.rollback() - tb_s = reduce(lambda x, y: x + y, - traceback.format_exception(*sys.exc_info())) + tb_s = ''.join(traceback.format_exception(*sys.exc_info())) logging.getLogger("convert").error( 'Could not delete id: %d of model %s\n' 'There should be some relation ' @@ -992,7 +991,7 @@ def post_import(pool, module, to_delete): 'You should manually fix this ' 'and restart --update=module\n' 'Exception: %s' % - (db_id, model, tb_s.decode('utf-8', 'ignore'))) + (db_id, model, tb_s)) transition_obj = pool.get('workflow.transition') for mdata_id, db_id in transition_delete: diff --git a/trytond/ir/cron.py b/trytond/ir/cron.py index 9e44af860a..d7e9aae545 100644 --- a/trytond/ir/cron.py +++ b/trytond/ir/cron.py @@ -104,8 +104,7 @@ class Cron(ModelSQL, ModelView): return _INTERVALTYPES[cron.interval_type](cron.interval_number) def _get_request_values(self, cron): - tb_s = reduce(lambda x, y: x + y, - traceback.format_exception(*sys.exc_info())) + tb_s = ''.join(traceback.format_exception(*sys.exc_info())) tb_s = tb_s.decode('utf-8', 'ignore') name = self.raise_user_error('request_title', raise_exception=False) diff --git a/trytond/model/modelstorage.py b/trytond/model/modelstorage.py index 7bf882bda6..beaec4965a 100644 --- a/trytond/model/modelstorage.py +++ b/trytond/model/modelstorage.py @@ -857,8 +857,7 @@ class ModelStorage(Model): logger.error(exp) # XXX should raise Exception Transaction().cursor.rollback() - tb_s = reduce(lambda x, y: x + y, - traceback.format_exception(*sys.exc_info())) + tb_s = ''.join(traceback.format_exception(*sys.exc_info())) warning = '%s\n%s' % (tb_s, warning) return (-1, res, exp, warning) done += 1 diff --git a/trytond/protocols/dispatcher.py b/trytond/protocols/dispatcher.py index a78b0ba2c6..b1e09d6609 100644 --- a/trytond/protocols/dispatcher.py +++ b/trytond/protocols/dispatcher.py @@ -165,13 +165,12 @@ def dispatch(host, port, protocol, database_name, user, session, object_type, if CONFIG['verbose'] and not isinstance(exception, ( NotLogged, ConcurrencyException, UserError, UserWarning)): - tb_s = reduce(lambda x, y: x + y, - traceback.format_exception(*sys.exc_info())) + tb_s = ''.join(traceback.format_exception(*sys.exc_info())) logger = logging.getLogger('dispatcher') logger.error('Exception calling method %s on ' \ '%s %s from %s@%s:%d/%s:\n' % \ (method, object_type, object_name, user, host, port, - database_name) + tb_s.decode('utf-8', 'ignore')) + database_name) + tb_s) transaction.cursor.rollback() raise if not (object_name == 'res.request' and method == 'request_get'): @@ -240,8 +239,7 @@ def create(database_name, password, lang, admin_password): res = True except Exception: logger.error('CREATE DB: %s failed' % (database_name,)) - tb_s = reduce(lambda x, y: x+y, - traceback.format_exception(*sys.exc_info())) + tb_s = ''.join(traceback.format_exception(*sys.exc_info())) logger.error('Exception in call: \n' + tb_s) raise else: @@ -263,8 +261,7 @@ def drop(database_name, password): cursor.commit() except Exception: logger.error('DROP DB: %s failed' % (database_name,)) - tb_s = reduce(lambda x, y: x+y, - traceback.format_exception(*sys.exc_info())) + tb_s = ''.join(traceback.format_exception(*sys.exc_info())) logger.error('Exception in call: \n' + tb_s) raise else: diff --git a/trytond/protocols/jsonrpc.py b/trytond/protocols/jsonrpc.py index 3358f1e8de..71d3efd6df 100644 --- a/trytond/protocols/jsonrpc.py +++ b/trytond/protocols/jsonrpc.py @@ -113,13 +113,7 @@ class SimpleJSONRPCDispatcher(SimpleXMLRPCServer.SimpleXMLRPCDispatcher): ConcurrencyException), exception: response['error'] = exception.args except Exception: - tb_s = '' - for line in traceback.format_exception(*sys.exc_info()): - try: - line = line.encode('utf-8', 'ignore') - except Exception: - continue - tb_s += line + tb_s = ''.join(traceback.format_exception(*sys.exc_info())) for path in sys.path: tb_s = tb_s.replace(path, '') if CONFIG['debug_mode']: diff --git a/trytond/protocols/webdav.py b/trytond/protocols/webdav.py index 641b928904..54ee809706 100644 --- a/trytond/protocols/webdav.py +++ b/trytond/protocols/webdav.py @@ -139,10 +139,9 @@ class TrytonDAVInterface(iface.dav_interface): if CONFIG['verbose'] and not isinstance(exception, ( NotLogged, ConcurrencyException, UserError, UserWarning, DAV_Error, DAV_NotFound, DAV_Secret, DAV_Forbidden)): - tb_s = reduce(lambda x, y: x + y, - traceback.format_exception(*sys.exc_info())) + tb_s = ''.join(traceback.format_exception(*sys.exc_info())) logger = logging.getLogger('webdav') - logger.error('Exception:\n' + tb_s.decode('utf-8', 'ignore')) + logger.error('Exception:\n' + tb_s) @staticmethod def get_dburi(uri): diff --git a/trytond/protocols/xmlrpc.py b/trytond/protocols/xmlrpc.py index def53a534a..65db29ab8e 100644 --- a/trytond/protocols/xmlrpc.py +++ b/trytond/protocols/xmlrpc.py @@ -113,13 +113,7 @@ class GenericXMLRPCRequestHandler: raise xmlrpclib.Fault(exception.code, '\n'.join((error,) + description)) except Exception: - tb_s = '' - for line in traceback.format_exception(*sys.exc_info()): - try: - line = line.encode('utf-8', 'ignore') - except Exception: - continue - tb_s += line + tb_s = ''.join(traceback.format_exception(*sys.exc_info())) for path in sys.path: tb_s = tb_s.replace(path, '') if CONFIG['debug_mode']: