]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
Shift exception formatting into the UI
authorChris Larson <chris_larson@mentor.com>
Fri, 6 May 2011 00:43:38 +0000 (17:43 -0700)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Wed, 8 Jun 2011 19:38:25 +0000 (20:38 +0100)
Now we use bb.exceptions to pass pickleable traceback entries to the UI, and
the UI is free to do whatever it wants to do with this information. By
default, the log formatter for the UIs formats it with bb.exceptions.  This
also means that all exceptions should now show 3 lines of context and limit to
5 entries.

(Bitbake rev: ee48d628ee038bd72e1cd94aa75f5ccbacbcee4c)

Signed-off-by: Chris Larson <chris_larson@mentor.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
bitbake/lib/bb/cooker.py
bitbake/lib/bb/event.py
bitbake/lib/bb/msg.py

index a15b81f233630849a51d362b4b0322c51b76de35..641a839810c5cd017523fd48f2b09179dcbbcf9c 100644 (file)
@@ -1225,7 +1225,7 @@ class CookerParser(object):
             raise
         except ParsingFailure as exc:
             self.shutdown(clean=False)
-            bb.fatal('Error parsing %s: %s' %
+            bb.fatal('Unable to parse %s: %s' %
                      (exc.recipe, bb.exceptions.to_string(exc.realexception)))
         except bb.parse.ParseError as exc:
             bb.fatal(str(exc))
@@ -1233,13 +1233,11 @@ class CookerParser(object):
             logger.error('Unable to parse %s', exc.recipe)
             sys.exit(1)
         except Exception as exc:
-            import traceback
             etype, value, tb = sys.exc_info()
-            formatted = bb.exceptions.format_extracted(value.traceback, limit=5)
-            formatted.extend(traceback.format_exception_only(etype, value))
-
+            logger.error('Unable to parse %s', value.recipe,
+                         exc_info=(etype, value, exc.traceback))
             self.shutdown(clean=False)
-            bb.fatal('Error parsing %s:\n%s' % (value.recipe, ''.join(formatted)))
+            sys.exit(1)
 
         self.current += 1
         self.virtuals += len(result)
index 4ff530fcb4d1866b760b1ae3e165e8a2439506e5..a3288b619b995af03c98cebfbd5258c931245731 100644 (file)
@@ -30,6 +30,7 @@ except ImportError:
     import pickle
 import logging
 import atexit
+import traceback
 import bb.utils
 
 # This is the pid for which we should generate the event. This is set when
@@ -423,6 +424,12 @@ class LogHandler(logging.Handler):
     """Dispatch logging messages as bitbake events"""
 
     def emit(self, record):
+        if record.exc_info:
+            etype, value, tb = record.exc_info
+            if hasattr(tb, 'tb_next'):
+                tb = list(bb.exceptions.extract_traceback(tb, context=3))
+            record.bb_exc_info = (etype, value, tb)
+            record.exc_info = None
         fire(record, None)
 
     def filter(self, record):
index a7ac850790df05bcf175244594b031e98d51c398..12d19ff8e119727e66ab06ab468d0e0c8abf7375 100644 (file)
@@ -65,9 +65,15 @@ class BBLogFormatter(logging.Formatter):
     def format(self, record):
         record.levelname = self.getLevelName(record.levelno)
         if record.levelno == self.PLAIN:
-            return record.getMessage()
+            msg = record.getMessage()
         else:
-            return logging.Formatter.format(self, record)
+            msg = logging.Formatter.format(self, record)
+
+        if hasattr(record, 'bb_exc_info'):
+            etype, value, tb = record.bb_exc_info
+            formatted = bb.exceptions.format_exception(etype, value, tb, limit=5)
+            msg += '\n' + ''.join(formatted)
+        return msg
 
 class Loggers(dict):
     def __getitem__(self, key):