From a1f53d8343b72f898b9a909cd78d40618b55738f Mon Sep 17 00:00:00 2001 From: Vincent Pelletier <vincent@nexedi.com> Date: Fri, 8 Feb 2008 12:28:30 +0000 Subject: [PATCH] Store exception information in native format inside message. Factorises sys.exc_info calls and exception rendering code. git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@19169 20353a03-c40f-0410-a6d1-a30d3c3de9de --- product/CMFActivity/Activity/SQLDict.py | 5 ++-- product/CMFActivity/Activity/SQLQueue.py | 5 ++-- product/CMFActivity/ActivityTool.py | 34 +++++++++++------------- 3 files changed, 21 insertions(+), 23 deletions(-) diff --git a/product/CMFActivity/Activity/SQLDict.py b/product/CMFActivity/Activity/SQLDict.py index 46c9fb0583..0c42093c7c 100644 --- a/product/CMFActivity/Activity/SQLDict.py +++ b/product/CMFActivity/Activity/SQLDict.py @@ -331,8 +331,9 @@ class SQLDict(RAMDict, SQLBase): if m.active_process: message_with_active_process_list.append(m) else: - if type(m.exc_type) is ClassType and \ - issubclass(m.exc_type, ConflictError): + exc_type = m.exc_info[0] + if type(exc_type) is ClassType and \ + issubclass(exc_type, ConflictError): delay_uid_list.append(uid) elif priority > MAX_PRIORITY: notify_user_list.append(m) diff --git a/product/CMFActivity/Activity/SQLQueue.py b/product/CMFActivity/Activity/SQLQueue.py index 5475f3aa49..e14ac476ea 100644 --- a/product/CMFActivity/Activity/SQLQueue.py +++ b/product/CMFActivity/Activity/SQLQueue.py @@ -198,8 +198,9 @@ class SQLQueue(RAMQueue, SQLBase): if m.active_process: message_with_active_process_list.append(m) else: - if type(m.exc_type) is ClassType and \ - issubclass(m.exc_type, ConflictError): + exc_type = m.exc_info[0] + if type(exc_type) is ClassType and \ + issubclass(exc_type, ConflictError): delay_uid_list.append(uid) elif priority > MAX_PRIORITY: notify_user_list.append(m) diff --git a/product/CMFActivity/ActivityTool.py b/product/CMFActivity/ActivityTool.py index 375b13aaae..d3f4430257 100644 --- a/product/CMFActivity/ActivityTool.py +++ b/product/CMFActivity/ActivityTool.py @@ -117,9 +117,7 @@ class Message: self.args = args self.kw = kw self.is_executed = 0 - self.exc_type = None - self.exc_value = None - self.traceback = None + self.exc_info = (None, None, None) self.processing = None self.user_name = str(_getAuthenticatedUser(self)) # Store REQUEST Info ? @@ -201,16 +199,13 @@ class Message: self.is_executed = 1 except: self.is_executed = 0 - self.exc_type = sys.exc_info()[0] - self.exc_value = str(sys.exc_info()[1]) - self.traceback = ''.join(ExceptionFormatter.format_exception( - *sys.exc_info())) + self.exc_info = sys.exc_info() LOG('ActivityTool', WARNING, 'Could not call method %s on object %s' % ( - self.method_id, self.object_path), error=sys.exc_info()) + self.method_id, self.object_path), error=self.exc_info) # push the error in ZODB error_log if getattr(activity_tool, 'error_log', None) is not None: - activity_tool.error_log.raising(sys.exc_info()) + activity_tool.error_log.raising(self.exc_info) def validate(self, activity, activity_tool, check_order_validation=1): return activity.validate(activity_tool, self, @@ -238,16 +233,17 @@ Subject: %s Document: %s Method: %s -Exception: %s %s %s """ % (activity_tool.email_from_address, user_email, message, message, '/'.join(self.object_path), self.method_id, - self.exc_type, self.exc_value, self.traceback) + ''.join(ExceptionFormatter.format_exception(*self.exc_info))) try: activity_tool.MailHost.send( mail_text ) - except (socket.error, MailHostError), message: - LOG('ActivityTool.notifyUser', WARNING, 'Mail containing failure information failed to be sent: %s. Exception was: %s %s\n%s' % (message, self.exc_type, self.exc_value, self.traceback)) + except (socket.error, MailHostError): + LOG('ActivityTool.notifyUser', WARNING, 'Mail containing failure information failed to be sent.', error=sys.exc_info()) + if self.exc_info[0] is not None: + LOG('ActivityTool.notifyUser', WARNING, 'Original exception', error=self.exc_info) def reactivate(self, activity_tool): # Reactivate the original object. @@ -843,10 +839,10 @@ class ActivityTool (Folder, UniqueObject): new_message_list.append(m) except: m.is_executed = 0 - m.exc_type = sys.exc_info()[0] + m.exc_info = sys.exc_info() LOG('WARNING ActivityTool', 0, 'Could not call method %s on object %s' % - (m.method_id, m.object_path), error=sys.exc_info()) + (m.method_id, m.object_path), error=m.exc_info) try: if len(expanded_object_list) > 0: @@ -861,10 +857,10 @@ class ActivityTool (Folder, UniqueObject): # In this case, the group method completely failed. for m in new_message_list: m.is_executed = 0 - m.exc_type = sys.exc_info()[0] + m.exc_info = sys.exc_info() LOG('WARNING ActivityTool', 0, 'Could not call method %s on objects %s' % - (method_id, expanded_object_list), error=sys.exc_info()) + (method_id, expanded_object_list), error=m.exc_info) else: # Obtain all indices of failed messages. Note that this can be a partial failure. failed_message_dict = {} @@ -888,10 +884,10 @@ class ActivityTool (Folder, UniqueObject): m.is_executed = 1 except: m.is_executed = 0 - m.exc_type = sys.exc_info()[0] + m.exc_info = sys.exc_info() LOG('ActivityTool', WARNING, 'Could not call method %s on object %s' % ( - m.method_id, m.object_path), error=sys.exc_info()) + m.method_id, m.object_path), error=m.exc_info) def newMessage(self, activity, path, active_process, activity_kw, method_id, *args, **kw): -- 2.30.9