Skip to contentSkip to conversation

bb.build: in _exec_task, catch errors from TaskStarted

PATCH In review Christopher Larson 2 participants 3 messages Sep 16, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bb.build: in _exec_task, catch errors from TaskStarted

From: Christopher Larson <[email protected]>

We want any exceptions raised by the TaskStarted event handlers to be caught rather than unconditionally hitting the exception formatting + traceback in exec_task, otherwise we can't cleanly exit the task with a nice message from such a handler.

This is done via a separate try/catch block, to avoid firing TaskFailed if all the TaskStarted event handlers didn't complete, otherwise the bitbake UIs get unhappy.

---
 lib/bb/build.py | 39 ++++++++++++++++++++++-----------------
 1 file changed, 22 insertions(+), 17 deletions(-)
lib/bb/build.py +22 -17
index 2ed0441..b74557a 100644
@@ -560,24 +560,29 @@ def _exec_task(fn, task, d, quieterr):
 
     flags = localdata.getVarFlags(task)
 
-    event.fire(TaskStarted(task, logfn, flags, localdata), localdata)
     try:
-        for func in (prefuncs or '').split():
-            exec_func(func, localdata)
-        exec_func(task, localdata)
-        for func in (postfuncs or '').split():
-            exec_func(func, localdata)
-    except FuncFailed as exc:
-        if quieterr:
-            event.fire(TaskFailedSilent(task, logfn, localdata), localdata)
-        else:
-            errprinted = errchk.triggered
-            logger.error(str(exc))
-            event.fire(TaskFailed(task, logfn, localdata, errprinted), localdata)
-        return 1
-    except bb.BBHandledException:
-        event.fire(TaskFailed(task, logfn, localdata, True), localdata)
-        return 1
+        try:
+            event.fire(TaskStarted(task, logfn, flags, localdata), localdata)
+        except BaseException:
+            return 1
+
+        try:
+            for func in (prefuncs or '').split():
+                exec_func(func, localdata)
+            exec_func(task, localdata)
+            for func in (postfuncs or '').split():
+                exec_func(func, localdata)
+        except FuncFailed as exc:
+            if quieterr:
+                event.fire(TaskFailedSilent(task, logfn, localdata), localdata)
+            else:
+                errprinted = errchk.triggered
+                logger.error(str(exc))
+                event.fire(TaskFailed(task, logfn, localdata, errprinted), localdata)
+            return 1
+        except bb.BBHandledException:
+            event.fire(TaskFailed(task, logfn, localdata, True), localdata)
+            return 1
     finally:
         sys.stdout.flush()
         sys.stderr.flush()
Signature · 1 line
2.8.0
#1 lore raw
Quoted 9 lines · Christopher Larson

From: Christopher Larson <[email protected]>

We want any exceptions raised by the TaskStarted event handlers to be caught
rather than unconditionally hitting the exception formatting + traceback in exec_task, otherwise we can't cleanly exit the task with a nice message from
such a handler.

Quoted 8 lines

This is done via a separate try/catch block, to avoid firing TaskFailed if all
the TaskStarted event handlers didn't complete, otherwise the bitbake UIs get
unhappy.

This supercedes 'bb.build: in _exec_task, catch BBHandledException’.

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

On Fri, Sep 16, 2016 at 1:01 PM, Christopher Larson <[email protected]

Quoted 21 lines

wrote:

Quoted 16 lines · Christopher Larson

From: Christopher Larson <[email protected]>

We want any exceptions raised by the TaskStarted event handlers to be caught
rather than unconditionally hitting the exception formatting + traceback in
exec_task, otherwise we can't cleanly exit the task with a nice message from
such a handler.

This is done via a separate try/catch block, to avoid firing TaskFailed if all
the TaskStarted event handlers didn't complete, otherwise the bitbake UIs get
unhappy.

Quoted 5 lines
Quoted 2 lines

This supercedes 'bb.build: in _exec_task, catch BBHandledException’.

Sigh, copy/paste error. This supercedes 'bb.build: in _exec_task, move TaskStarted into try/except’. We want this and the BBHandledException patch both applied. I’ll just send a v2 to avoid confusion :)

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