diff options
author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2011-02-23 13:13:31 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2011-02-23 13:13:31 +0000 |
commit | 101b599110f7bc29f52a14a968f30323aeb797ca (patch) | |
tree | 2ed171b52eab7961215f105eb9982b7fa128ae68 /bitbake/lib/bb/data_smart.py | |
parent | 6ea24f04cd635295d826f03d9c7d8a08cc1d5b31 (diff) | |
download | poky-101b599110f7bc29f52a14a968f30323aeb797ca.tar.gz |
bitbake/data_smart: Improve Variable expansion error handling
If expanding a variable triggers an exception the caller currently has no
way to supress the error message or otherwise handle the siutation. An
example of where this is a problem is "bitbake -e" showing tracebacks and
errors for variables like SRCPV in OE/Poky.
Secondly in a chained expansion fails, log mesages are recorded for
every step of the expansion, not just the innermost error which is
where the real failure occured.
To fix this we introduce a new exception ExpansionError which callers
can handle as appropriate.
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/data_smart.py')
-rw-r--r-- | bitbake/lib/bb/data_smart.py | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/bitbake/lib/bb/data_smart.py b/bitbake/lib/bb/data_smart.py index e76fbbf6ce..df9798ad58 100644 --- a/bitbake/lib/bb/data_smart.py +++ b/bitbake/lib/bb/data_smart.py | |||
@@ -90,6 +90,17 @@ class DataContext(dict): | |||
90 | else: | 90 | else: |
91 | return value | 91 | return value |
92 | 92 | ||
93 | class ExpansionError(Exception): | ||
94 | def __init__(self, varname, expression, exception): | ||
95 | self.expression = expression | ||
96 | self.variablename = varname | ||
97 | self.exception = exception | ||
98 | self.msg = "Failure expanding variable %s, expression was %s which triggered exception %s: %s" % (varname, expression, type(exception).__name__, exception) | ||
99 | Exception.__init__(self, self.msg) | ||
100 | self.args = (varname, expression, exception) | ||
101 | def __str__(self): | ||
102 | return self.msg | ||
103 | |||
93 | class DataSmart(MutableMapping): | 104 | class DataSmart(MutableMapping): |
94 | def __init__(self, special = COWDictBase.copy(), seen = COWDictBase.copy() ): | 105 | def __init__(self, special = COWDictBase.copy(), seen = COWDictBase.copy() ): |
95 | self.dict = {} | 106 | self.dict = {} |
@@ -117,9 +128,10 @@ class DataSmart(MutableMapping): | |||
117 | s = __expand_python_regexp__.sub(varparse.python_sub, s) | 128 | s = __expand_python_regexp__.sub(varparse.python_sub, s) |
118 | if s == olds: | 129 | if s == olds: |
119 | break | 130 | break |
120 | except Exception: | 131 | except ExpansionError: |
121 | logger.exception("Error evaluating '%s'", s) | ||
122 | raise | 132 | raise |
133 | except Exception as exc: | ||
134 | raise ExpansionError(varname, s, exc) | ||
123 | 135 | ||
124 | varparse.value = s | 136 | varparse.value = s |
125 | 137 | ||