From: Chris Larson Date: Fri, 6 May 2011 00:43:38 +0000 (-0700) Subject: Shift exception formatting into the UI X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ee48d628ee038bd72e1cd94aa75f5ccbacbcee4c;p=thirdparty%2Fopenembedded%2Fopenembedded-core-contrib.git Shift exception formatting into the UI 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. Signed-off-by: Chris Larson --- diff --git a/lib/bb/cooker.py b/lib/bb/cooker.py index 5d2f2a88e68..e0e8bf55ad7 100644 --- a/lib/bb/cooker.py +++ b/lib/bb/cooker.py @@ -1125,7 +1125,7 @@ class CookerParser(object): return False 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)) @@ -1133,13 +1133,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) diff --git a/lib/bb/event.py b/lib/bb/event.py index daca0a77071..16d936c1b6f 100644 --- a/lib/bb/event.py +++ b/lib/bb/event.py @@ -422,8 +422,10 @@ class LogHandler(logging.Handler): def emit(self, record): if record.exc_info: - lines = traceback.format_exception(*record.exc_info, limit=5) - record.msg += '\n%s' % ''.join(lines) + 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) diff --git a/lib/bb/msg.py b/lib/bb/msg.py index a7ac850790d..12d19ff8e11 100644 --- a/lib/bb/msg.py +++ b/lib/bb/msg.py @@ -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):