From 1bf517b461e4a0a16678f0069b1d3df99265e2c9 Mon Sep 17 00:00:00 2001
From: Vincent Pelletier <vincent@nexedi.com>
Date: Tue, 7 Oct 2008 16:40:25 +0000
Subject: [PATCH] Store exception information on message in the case where
 commit fails, removing a possible cause for error messages with no error
 text.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@24077 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/CMFActivity/Activity/SQLDict.py  | 9 +++++++++
 product/CMFActivity/Activity/SQLQueue.py | 6 ++++++
 2 files changed, 15 insertions(+)

diff --git a/product/CMFActivity/Activity/SQLDict.py b/product/CMFActivity/Activity/SQLDict.py
index e0f70d4f10..b8c7262755 100644
--- a/product/CMFActivity/Activity/SQLDict.py
+++ b/product/CMFActivity/Activity/SQLDict.py
@@ -38,6 +38,7 @@ from types import ClassType
 #from time import time
 from SQLBase import SQLBase
 from Products.CMFActivity.ActivityRuntimeEnvironment import setActivityRuntimeValue, updateActivityRuntimeValue, clearActivityRuntimeEnvironment
+from zExceptions import ExceptionFormatter
 
 try:
   from transaction import get as get_transaction
@@ -491,8 +492,16 @@ class SQLDict(RAMDict, SQLBase):
           except:
             LOG('SQLDict', PANIC, 'Failed to abort executed messages which also failed to commit. Some objects may be modified accidentally.')
             raise
+        exc_info = sys.exc_info()
+        exc_type = exc_info[0]
+        exc_value = str(exc_info[1])
+        traceback = ''.join(ExceptionFormatter.format_exception(
+                            *exc_info))
         for x in message_uid_priority_list:
           x[1].is_executed = MESSAGE_NOT_EXECUTED
+          x[1].exc_type = exc_type
+          x[1].exc_value = exc_value
+          x[1].traceback = traceback
         failed_message_uid_list = [x[0] for x in message_uid_priority_list]
         try:
           makeMessageListAvailable(failed_message_uid_list, uid_to_duplicate_uid_list_dict)
diff --git a/product/CMFActivity/Activity/SQLQueue.py b/product/CMFActivity/Activity/SQLQueue.py
index fb2e79137e..e2f92e16ef 100644
--- a/product/CMFActivity/Activity/SQLQueue.py
+++ b/product/CMFActivity/Activity/SQLQueue.py
@@ -39,6 +39,7 @@ from time import time
 from sets import ImmutableSet
 from SQLBase import SQLBase
 from Products.CMFActivity.ActivityRuntimeEnvironment import setActivityRuntimeValue, updateActivityRuntimeValue, clearActivityRuntimeEnvironment
+from zExceptions import ExceptionFormatter
 
 try:
   from transaction import get as get_transaction
@@ -320,6 +321,11 @@ class SQLQueue(RAMQueue, SQLBase):
           # It is possible that the message is executed but the commit
           # of the transaction fails
           value[1].is_executed = MESSAGE_NOT_EXECUTED
+          exc_info = sys.exc_info()
+          value[1].exc_type = exc_info[0]
+          value[1].exc_value = str(exc_info[1])
+          value[1].traceback = ''.join(ExceptionFormatter.format_exception(
+                                       *exc_info))
           try:
             makeMessageListAvailable([value[0]])
           except:
-- 
2.30.9