diff options
author | Richard Purdie <rpurdie@linux.intel.com> | 2010-12-05 22:52:44 +0000 |
---|---|---|
committer | Chris Larson <chris_larson@mentor.com> | 2010-12-17 13:19:16 -0700 |
commit | 70cba0e84da29fa49bc232a8a6185a75a300bce8 (patch) | |
tree | 02d7b77c72bdd8871c336aefa9eb6eb6906859db | |
parent | 33e36916dfda773d92f6b0f2bbbda00cc07f9261 (diff) | |
download | bitbake-70cba0e84da29fa49bc232a8a6185a75a300bce8.tar.gz |
bitbake/utils.py: Improve traceback to be more helpful/clear to users
Signed-off-by: Richard Purdie <rpurdie@linux.intel.com>
-rw-r--r-- | lib/bb/utils.py | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/lib/bb/utils.py b/lib/bb/utils.py index f5e4b60ab..d5028e19c 100644 --- a/lib/bb/utils.py +++ b/lib/bb/utils.py @@ -342,21 +342,38 @@ def better_exec(code, context, text, realfile = "<code>"): if t in [bb.parse.SkipPackage, bb.build.FuncFailed]: raise - logger.exception("Error executing python function in '%s'", code.co_filename) + logger.error('There was an error when executing a python function in: %s', realfile) # Strip 'us' from the stack (better_exec call) tb = tb.tb_next import traceback + textarray = text.split('\n') + linefailed = traceback.tb_lineno(tb) + tbextract = traceback.extract_tb(tb) - tbextract = "\n".join(traceback.format_list(tbextract)) - bb.msg.error(bb.msg.domain.Util, "Traceback:") - for line in tbextract.split('\n'): - bb.msg.error(bb.msg.domain.Util, line) - - line = traceback.tb_lineno(tb) - bb.msg.error(bb.msg.domain.Util, "The lines leading to this error were:") - _print_trace( text.split('\n'), line ) + tbformat = "\n".join(traceback.format_list(tbextract)) + logger.error("The stack trace of python calls that resulted in thie exception/failure was:") + for line in tbformat.split('\n'): + logger.error(line) + + logger.error("The code that was being executed was:") + _print_trace(textarray, linefailed) + logger.error("(file: '%s', lineno: %s, function: %s)", tbextract[0][0], tbextract[0][1], tbextract[0][2]) + + # See if this is a function we constructed and has calls back into other functions in + # "text". If so, try and improve the context of the error by diving down the trace + level = 0 + nexttb = tb.tb_next + while nexttb is not None: + if tbextract[level][0] == tbextract[level+1][0] and tbextract[level+1][2] == tbextract[level][0]: + _print_trace(textarray, tbextract[level+1][1]) + logger.error("(file: '%s', lineno: %s, function: %s)", tbextract[level+1][0], tbextract[level+1][1], tbextract[level+1][2]) + else: + break + nexttb = tb.tb_next + level = level + 1 + raise def simple_exec(code, context): |