Create catalyst.util module with capture_traceback() and print_traceback() functions
authoragaffney <agaffney@kagome.(none)>
Sun, 7 Sep 2008 19:23:29 +0000 (14:23 -0500)
committeragaffney <agaffney@kagome.(none)>
Sun, 7 Sep 2008 19:23:29 +0000 (14:23 -0500)
Capture and print traceback when build fails instead of letting python do it

ChangeLog
catalyst
modules/catalyst/util.py [new file with mode: 0644]

index 0fb54146465f2e2ab1de2fae916d2993dbb86d04..6f5c99d26b5498bf860fd9e1003944963a7c36d8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,12 @@
 # Copyright 2002-2008 Gentoo Foundation; Distributed under the GPL v2
 # $Id: $
 
+  07 Sep 2008; Andrew Gaffney <agaffney@gentoo.org> catalyst,
+  +modules/catalyst/util.py:
+  Create catalyst.util module with capture_traceback() and print_traceback()
+  functions Capture and print traceback when build fails instead of letting
+  python do it
+
   07 Sep 2008; Andrew Gaffney <agaffney@gentoo.org> catalyst,
   modules/catalyst/config.py, modules/catalyst_support.py:
   Switch commandline spec value parsing to use catalyst.config.ConfigParser
index 08706063ef549049dbb5627916f4583ca87d9996..c8b0a07d80bca905df413708dbb1c036a3d23b9d 100755 (executable)
--- a/catalyst
+++ b/catalyst
@@ -10,6 +10,7 @@ import pdb
 sys.path.append("./modules")
 
 import catalyst.config
+import catalyst.util
 
 __maintainer__="Chris Gianelloni <wolf31o2@gentoo.org>"
 __version__="2.0.6"
@@ -203,9 +204,9 @@ def build_target(addlargs, targetmap):
                mytarget.run()
 
        except:
-               # TODO: Capture traceback, so we can display this error after printing of the traceback
+               catalyst.util.print_traceback()
                print "!!! catalyst: Error encountered during run of target " + addlargs["target"]
-               raise
+               sys.exit(1)
 
 if __name__ == "__main__":
        targetmap={}
diff --git a/modules/catalyst/util.py b/modules/catalyst/util.py
new file mode 100644 (file)
index 0000000..ff12086
--- /dev/null
@@ -0,0 +1,14 @@
+"""
+Collection of utility functions for catalyst
+"""
+
+import sys, traceback
+
+def capture_traceback():
+       etype, value, tb = sys.exc_info()
+       s = [x.strip() for x in traceback.format_exception(etype, value, tb)]
+       return s
+
+def print_traceback():
+       for x in capture_traceback():
+               print x