aboutsummaryrefslogtreecommitdiffstats
path: root/lib/bb
diff options
context:
space:
mode:
authorChris Larson <chris_larson@mentor.com>2011-04-04 13:51:51 -0700
committerChris Larson <chris_larson@mentor.com>2011-04-04 14:23:09 -0700
commit156ea134e82d873ca4b5343261da2291a2b32ef6 (patch)
treed3639c80e22bfde9888d975216583f3902139f98 /lib/bb
parentfaf682dfc23b7ef2ece04f7d50f9741224bb3bb0 (diff)
downloadbitbake-156ea134e82d873ca4b5343261da2291a2b32ef6.tar.gz
event: improve output for syntax errors in handlers
Note: this includes IndentationError, which is a subclass of SyntaxError. Signed-off-by: Chris Larson <chris_larson@mentor.com>
Diffstat (limited to 'lib/bb')
-rw-r--r--lib/bb/event.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/bb/event.py b/lib/bb/event.py
index 498a424a..daca0a77 100644
--- a/lib/bb/event.py
+++ b/lib/bb/event.py
@@ -151,6 +151,7 @@ def fire_from_worker(event, d):
event = pickle.loads(event[7:-8])
fire_ui_handlers(event, d)
+noop = lambda _: None
def register(name, handler):
"""Register an Event handler"""
@@ -162,10 +163,15 @@ def register(name, handler):
# handle string containing python code
if isinstance(handler, basestring):
tmp = "def %s(e):\n%s" % (name, handler)
- comp = bb.utils.better_compile(tmp, "%s(e)" % name,
- "bb.event._registerCode")
+ try:
+ code = compile(tmp, "%s(e)" % name, "exec")
+ except SyntaxError:
+ logger.error("Unable to register event handler '%s':\n%s", name,
+ ''.join(traceback.format_exc(limit=0)))
+ _handlers[name] = noop
+ return
env = {}
- bb.utils.simple_exec(comp, env)
+ bb.utils.simple_exec(code, env)
func = bb.utils.better_eval(name, env)
_handlers[name] = func
else: