[bitbake-devel] [PATCH 2/2] bb.cookerdata: include useful traceback for ExpansionError/ParseError

Christopher Larson chris_larson at mentor.com
Mon Aug 24 22:48:04 UTC 2015


On Mon, Aug 24, 2015 at 3:32 PM, Christopher Larson <kergoth at gmail.com>
wrote:

> From: Christopher Larson <chris_larson at mentor.com>
>
> Show the user only the portion of the traceback which was from the
> metadata,
> nothing from bitbake's internal calls.
>
> Signed-off-by: Christopher Larson <chris_larson at mentor.com>
> ---
>  lib/bb/cookerdata.py | 11 ++++++++++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/lib/bb/cookerdata.py b/lib/bb/cookerdata.py
> index 57fc6bb..a033266 100644
> --- a/lib/bb/cookerdata.py
> +++ b/lib/bb/cookerdata.py
> @@ -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
>


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.
-- 
Christopher Larson
kergoth at gmail dot com
Founder - BitBake, OpenEmbedded, OpenZaurus
Maintainer - Tslib
Senior Software Engineer, Mentor Graphics
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openembedded.org/pipermail/bitbake-devel/attachments/20150824/e9fb51c3/attachment-0002.html>


More information about the bitbake-devel mailing list