[SCM] morituri/master: * morituri/common/task.py: Wrap exceptions during tasks in a TaskException, storing the message, for improved error reporting later on.

js at users.alioth.debian.org js at users.alioth.debian.org
Sun Oct 19 20:09:16 UTC 2014


The following commit has been merged in the master branch:
commit 6ae35a7a08eb202597e2f03b8337b7b7bea17b41
Author: Thomas Vander Stichele <thomas (at) apestaart (dot) org>
Date:   Sun Apr 4 23:10:44 2010 +0000

    	* morituri/common/task.py:
    	  Wrap exceptions during tasks in a TaskException, storing the
    	  message, for improved error reporting later on.

diff --git a/ChangeLog b/ChangeLog
index b8f0b29..179c4ad 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2010-04-05  Thomas Vander Stichele  <thomas at apestaart dot org>
 
+	* morituri/common/task.py:
+	  Wrap exceptions during tasks in a TaskException, storing the
+	  message, for improved error reporting later on.
+
+2010-04-05  Thomas Vander Stichele  <thomas at apestaart dot org>
+
 	* doc/Makefile.am:
 	* morituri.spec.in:
 	* morituri/extern/Makefile.am:
diff --git a/morituri/common/task.py b/morituri/common/task.py
index 1541830..0dbef2f 100644
--- a/morituri/common/task.py
+++ b/morituri/common/task.py
@@ -26,6 +26,18 @@ import gobject
 
 from morituri.common import log
 
+class TaskException(Exception):
+    """
+    I wrap an exception that happened during task execution.
+    """
+
+    exception = None # original exception
+
+    def __init__(self, exception, message=None):
+        self.exception = exception
+        self.exceptionMessage = message
+        self.args = (exception, message, )
+
 class Task(object, log.Loggable):
     """
     I wrap a task in an asynchronous interface.
@@ -94,6 +106,11 @@ class Task(object, log.Loggable):
             self._notifyListeners('described', description)
             self.description = description
 
+    def setException(self, exception):
+        self.exception = exception
+        self.exceptionMessage = log.getExceptionMessage(exception)
+        self.debug('set exception, %r' % self.exceptionMessage)
+
     def addListener(self, listener):
         """
         Add a listener for task status changes.
@@ -214,10 +231,8 @@ class BaseMultiTask(Task, ITaskListener):
             task.addListener(self)
             task.start(self.runner)
         except Exception, e:
-            m = log.getExceptionMessage(e)
-            self.debug('Got exception during next: %r', m)
-            self.exception = e
-            self.exceptionMessage = m
+            self.setException(e)
+            self.debug('Got exception during next: %r', self.exceptionMessage)
             self.stop()
             return
         
@@ -235,8 +250,10 @@ class BaseMultiTask(Task, ITaskListener):
         """
         self.log('BaseMultiTask.stopped: task %r', task)
         if task.exception:
-            self.log('BaseMultiTask.stopped: exception %r', task.exception)
+            self.log('BaseMultiTask.stopped: exception %r',
+                task.exceptionMessage)
             self.exception = task.exception
+            self.exceptionMessage = task.exceptionMessage
             self.stop()
             return
 
@@ -346,9 +363,10 @@ class SyncRunner(TaskRunner, ITaskListener):
 
         self.debug('done running task %r', task)
         if task.exception:
+            # catch the exception message
             # FIXME: this gave a traceback in the logging module
             self.debug('raising exception, %r', task.exceptionMessage)
-            raise task.exception
+            raise TaskException(task.exception, message=task.exceptionMessage)
 
     def _startWrap(self, task):
         # wrap task start such that we can report any exceptions and
@@ -358,10 +376,8 @@ class SyncRunner(TaskRunner, ITaskListener):
         except Exception, e:
             # getExceptionMessage uses global exception state that doesn't
             # hang around, so store the message
-            m = log.getExceptionMessage(e)
-            self.debug('exception during start: %r', m)
-            task.exception = e
-            task.exceptionMessage = m
+            task.setException(e)
+            self.debug('exception during start: %r', task.exceptionMessage)
             self.stopped(task)
 
 

-- 
morituri packaging



More information about the pkg-multimedia-commits mailing list