fixed msger.PrintBufWrapper: proper handle of exceptions
authorJF Ding <jian-feng.ding@intel.com>
Mon, 20 Feb 2012 11:21:48 +0000 (19:21 +0800)
committerJF Ding <jian-feng.ding@intel.com>
Mon, 20 Feb 2012 11:22:47 +0000 (19:22 +0800)
catch the exception, stop the wrapper and print out the err
message, then raise forward

gitbuildsys/msger.py

index 1f7d28d..93e5399 100644 (file)
@@ -149,12 +149,17 @@ class PrintBufWrapper(object):
         if callable(orig_attr):
             def hooked(*args, **kwargs):
                 self.pbuf.start()
-                result = orig_attr(*args, **kwargs)
-                stdout_msg, stderr_msg = self.pbuf.stop()
-                if stdout_msg:
-                    self.func1(stdout_msg)
-                if stderr_msg:
-                    self.func2(stderr_msg)
+                try:
+                    result = orig_attr(*args, **kwargs)
+                except:
+                    raise
+                finally:
+                    stdout_msg, stderr_msg = self.pbuf.stop()
+                    if stdout_msg:
+                        self.func1(stdout_msg)
+                    if stderr_msg:
+                        self.func2(stderr_msg)
+
                 return result
 
             return hooked