Skip to contentSkip to conversation

bb.data_smart: retain traceback from ExpansionError

PATCH In review Christopher Larson 2 participants 3 messages Aug 24, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 bb.data_smart: retain traceback from ExpansionError

From: Christopher Larson <[email protected]>

This gives us the needed context of the original ExpansionError, which is invaluable when we have a chain of function calls in the expansion.

---
 lib/bb/data_smart.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
lib/bb/data_smart.py +2 -1
index 26f69d1..6fac82e 100644
@@ -367,7 +367,8 @@ class DataSmart(MutableMapping):
             except bb.parse.SkipRecipe:
                 raise
             except Exception as exc:
-                raise ExpansionError(varname, s, exc)
+                exc_class, exc, tb = sys.exc_info()
+                raise ExpansionError, ExpansionError(varname, s, exc), tb
 
         varparse.value = s
 
Signature · 1 line
2.2.1
#1 lore raw

PATCH 2/2 bb.cookerdata: include useful traceback for ExpansionError/ParseError

From: Christopher Larson <[email protected]>

Show the user only the portion of the traceback which was from the metadata, nothing from bitbake's internal calls.

---
 lib/bb/cookerdata.py | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
lib/bb/cookerdata.py +10 -1
index 57fc6bb..a033266 100644
@@ -179,7 +179,16 @@ def catch_parse_error(func):
             parselog.critical("Unable to parse %s: %s" % (fn, exc))
             sys.exit(1)
         except (bb.parse.ParseError, bb.data_smart.ExpansionError) as exc:
-            parselog.critical("Unable to parse %s: %s" % (fn, exc))
+            import traceback
+
+            bbdir = os.path.dirname(__file__) + os.sep
+            exc_class, exc, tb = sys.exc_info()
+            for tb in iter(lambda: tb.tb_next, None):
+                # Skip frames in bitbake itself, we only want the metadata
+                fn, _, _, _ = traceback.extract_tb(tb, 1)[0]
+                if not fn.startswith(bbdir):
+                    break
+            parselog.critical("Unable to parse %s", fn, exc_info=(exc_class, exc, tb))
             sys.exit(1)
     return wrapped
 
Signature · 1 line
2.2.1
#2 lore raw

Re: [PATCH 2/2] bb.cookerdata: include useful traceback for ExpansionError/ParseError

Quoted 24 lines · Christopher Larson

From: Christopher Larson <[email protected]>

Show the user only the portion of the traceback which was from the metadata,
nothing from bitbake's internal calls.

---
 lib/bb/cookerdata.py | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
lib/bb/cookerdata.py +3 -1
index 57fc6bb..a033266 100644
@@ -179,7 +179,16 @@ def catch_parse_error(func):
             parselog.critical("Unable to parse %s: %s" % (fn, exc))
             sys.exit(1)
         except (bb.parse.ParseError, bb.data_smart.ExpansionError) as exc:
-            parselog.critical("Unable to parse %s: %s" % (fn, exc))
+            import traceback
+
+            bbdir = os.path.dirname(__file__) + os.sep

lib/bb/cookerdata.py def catch_parse_error(func): · line 194

Quoted 10 lines
lib/bb/cookerdata.py +7 -0
+            exc_class, exc, tb = sys.exc_info()
+            for tb in iter(lambda: tb.tb_next, None):
+                # Skip frames in bitbake itself, we only want the metadata
+                fn, _, _, _ = traceback.extract_tb(tb, 1)[0]
+                if not fn.startswith(bbdir):
+                    break
+            parselog.critical("Unable to parse %s", fn,
 exc_info=(exc_class, exc, tb))
             sys.exit(1)
     return wrapped

Before:

$ bitbake -p
ERROR: Unable to parse conf/bitbake.conf: Failure expanding variable
FOO[:=], expression was ${@foo(d)} which triggered exception NameError:
global name 'sys' is not defined

After:

$ bitbake -p
ERROR: Unable to parse FOO[:=]
Traceback (most recent call last):
  File "FOO[:=]", line 1, in <module>
  File "test.inc", line 2, in foo(d=<bb.data_smart.DataSmart object at
0x99ff6cc>)
  File "test.inc", line 2, in bar(d=<bb.data_smart.DataSmart object at
0x99ff6cc>)
ExpansionError: Failure expanding variable FOO[:=], expression was
${@foo(d)} which triggered exception NameError: global name 'sys' is not
defined

There's still room for improvement, obviously. I'd like those filenames and line numbers to be correct absolute paths with correct adjusted line numbers and something other than <module> for the "function" of a :=, possibly, but it's a start.

Signature · 5 lines
Christopher Larson
kergoth at gmail dot com
Founder - BitBake, OpenEmbedded, OpenZaurus
Maintainer - Tslib
Senior Software Engineer, Mentor Graphics