Skip to contentSkip to conversation

process: Improve traceback error reporting from main loop

PATCH New Richard Purdie 1 participant 4 messages Aug 5, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 process: Improve traceback error reporting from main loop

Currently the code can just show nothing as the exception if there was a double fault, which in this code path is quite likely. This leads to an error log which effectively says "it failed" with no information about how.

Improve things so we get a nice verbose traceback left in the logs/output which is preferable to no logs.

---
 lib/bb/server/process.py | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
lib/bb/server/process.py +4 -2
index a0955722e3..6127fd40e6 100644
@@ -26,6 +26,7 @@ import errno
 import re
 import datetime
 import pickle
+import traceback
 import bb.server.xmlrpcserver
 from bb import daemonize
 from multiprocessing import queues
@@ -217,8 +218,9 @@ class ProcessServer():
                     self.command_channel_reply.send(self.cooker.command.runCommand(command))
                     serverlog("Command Completed")
                 except Exception as e:
-                   serverlog('Exception in server main event loop running command %s (%s)' % (command, str(e)))
-                   logger.exception('Exception in server main event loop running command %s (%s)' % (command, str(e)))
+                   stack = traceback.format_exc()
+                   serverlog('Exception in server main event loop running command %s (%s)' % (command, stack))
+                   logger.exception('Exception in server main event loop running command %s (%s)' % (command, stack))
 
             if self.xmlrpc in ready:
                 self.xmlrpc.handle_requests()
Signature · 1 line
2.30.2
#1 lore raw

PATCH 2/4 command: Ensure we catch/handle exceptions

If an exception occurs in early setup, bitbake could just hang. Return the exception rather than doing that.

[YOCTO #14408]

---
 lib/bb/command.py | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
lib/bb/command.py +11 -3
index f530cf844b..a81dcb1366 100644
@@ -65,9 +65,17 @@ class Command:
 
         # Ensure cooker is ready for commands
         if command != "updateConfig" and command != "setFeatures":
-            self.cooker.init_configdata()
-            if not self.remotedatastores:
-                self.remotedatastores = bb.remotedata.RemoteDatastores(self.cooker)
+            try:
+                self.cooker.init_configdata()
+                if not self.remotedatastores:
+                    self.remotedatastores = bb.remotedata.RemoteDatastores(self.cooker)
+            except (Exception, SystemExit) as exc:
+                import traceback
+                if isinstance(exc, bb.BBHandledException):
+                    # We need to start returning real exceptions here. Until we do, we can't
+                    # tell if an exception is an instance of bb.BBHandledException
+                    return None, "bb.BBHandledException()\n" + traceback.format_exc()
+                return None, traceback.format_exc()
 
         if hasattr(CommandsSync, command):
             # Can run synchronous commands straight away
Signature · 1 line
2.30.2
#2 lore raw

PATCH 3/4 ui/taskexp: Improve startup exception handling

In reply to Richard Purdie

When an exception occurs at startup, show it to the user.

[YOCTO #14408]

---
 lib/bb/ui/taskexp.py | 4 ++++
 1 file changed, 4 insertions(+)
lib/bb/ui/taskexp.py +4 -0
index 2b246710ca..81392977a0 100644
@@ -8,6 +8,7 @@
 #
 
 import sys
+import traceback
 
 try:
     import gi
@@ -218,6 +219,9 @@ def main(server, eventHandler, params):
     except client.Fault as x:
         print("XMLRPC Fault getting commandline:\n %s" % x)
         return
+    except Exception as e:
+        print("Exception in startup:\n %s" % traceback.format_exc())
+        return
 
     if gtkthread.quit.isSet():
         return
Signature · 1 line
2.30.2
#3 lore raw

PATCH 4/4 ui/taskexp: Fix to work with empty build directories

In reply to Richard Purdie

If run on an empty build directory, taskexp wasn't working as it didn't send the current environment to the server. This means HOSTTOOLS in oe-core couldn't be built and gave an error. Add the missing updateToServer call in.

[YOCTO #14408]

---
 lib/bb/ui/taskexp.py | 1 +
 1 file changed, 1 insertion(+)
lib/bb/ui/taskexp.py +1 -0
index 81392977a0..c00eaf6638 100644
@@ -197,6 +197,7 @@ def main(server, eventHandler, params):
     gtkgui.start()
 
     try:
+        params.updateToServer(server, os.environ.copy())
         params.updateFromServer(server)
         cmdline = params.parseActions()
         if not cmdline:
Signature · 1 line
2.30.2