Skip to contentSkip to conversation

oe/utils: log exceptions in ThreadedWorker functions

PATCH New Ross Burton 1 participant 2 messages Oct 14, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 oe/utils: log exceptions in ThreadedWorker functions

If the function a ThreadedWorker is executing raises an exception, don't use print() as that mostly disappears. Instead, output it to the logger.

This is done using bb.mainlogger.debug directly instead of bb.debug() as this allows us to pass the exception instance directly, which is then incorporated into the log stream.

---
 meta/lib/oe/utils.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
meta/lib/oe/utils.py +2 -1
index 238af314d1..cf65639647 100644
@@ -508,7 +508,8 @@ class ThreadedWorker(Thread):
             try:
                 func(self, *args, **kargs)
             except Exception as e:
-                print(e)
+                # Eat all exceptions
+                bb.mainlogger.debug("Worker task raised %s" % e, exc_info=e)
             finally:
                 self.tasks.task_done()
 
Signature · 1 line
2.25.1
#1 lore raw

PATCH 2/2 sstate: don't silently handle all exceptions in sstate_checkhashes

If checkstatus returns an exception we should silently handle FetchError, as this means the fetch failed for 'normal' reasons such as file not found. However, other exceptions may be raised, and these should be made visible.

---
 meta/classes/sstate.bbclass | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
meta/classes/sstate.bbclass +4 -3
index 701a19bc61..143819b898 100644
@@ -983,10 +983,11 @@ def sstate_checkhashes(sq_data, d, siginfo=False, currentcount=0, summary=True,
                 foundNet.add(tid)
                 if tid in missed:
                     missed.remove(tid)
-            except:
+            except bb.fetch2.FetchError as e:
                 missed.add(tid)
-                bb.debug(2, "SState: Unsuccessful fetch test for %s" % srcuri)
-                pass
+                bb.debug(2, "SState: Unsuccessful fetch test for %s (%s)" % (srcuri, e))
+            except Exception as e:
+                bb.error("SState: cannot test %s: %s" % (srcuri, e))
             if len(tasklist) >= min_tasks:
                 bb.event.fire(bb.event.ProcessProgress(msg, len(tasklist) - thread_worker.tasks.qsize()), d)
 
Signature · 1 line
2.25.1