Skip to contentSkip to conversation

bitbake: fix wrong usage of format_exc

PATCH Superseded Ed Bartosh 1 participant 2 messages Jun 10, 2016

lore
Share & tools
lore

Ed Bartosh

author
#0 lore raw

PATCH 1/1 bitbake: fix wrong usage of format_exc

From: Ed Bartosh <[email protected]>

First parameter of traceback.format_exc APIs is a 'limit' - a number of stracktraces to print.

Passing exception object to print_exc or format_exc is incorrect, but it works in Python 2 and causes printing only one line of traceback as exception object is compared with the integer counter in the traceback module code.

In Python 3 comparison of integer and exception object throws an exception:
TypeError: unorderable types: int() < <Exception type>()

As format_exc is used in except block of handling another exception this can cause hard to find and debug bugs.

---
 lib/bb/ui/uievent.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/bb/ui/uievent.py +1 -1
index ca19166..9542b91 100644
@@ -116,7 +116,7 @@ class BBUIEventQueue:
                 self.server.handle_request()
             except Exception as e:
                 import traceback
-                logger.error("BBUIEventQueue.startCallbackHandler: Exception while trying to handle request: %s\n%s" % (e, traceback.format_exc(e)))
+                logger.error("BBUIEventQueue.startCallbackHandler: Exception while trying to handle request: %s\n%s" % (e, traceback.format_exc()))
 
         self.server.server_close()
 
Signature · 1 line
2.1.4
author
#1 lore raw

PATCH v2 1/1 bitbake: fix wrong usage of format_exc

From: Ed Bartosh <[email protected]>

First parameter of traceback.format_exc is a 'limit' - a number of stracktraces to format.

Passing exception object to format_exc is incorrect, but it works in Python 2 as this code from traceback module works:
while tb is not None and (limit is None or n < limit):
Comparing integer counter n with the exception object in Python 2 always results in True. However, in Python 3 it throws exception:
TypeError: unorderable types: int() < <Exception type>()

As format_exc is used in except block of handling another exception this can cause hard to find and debug bugs.

---
 lib/bb/cooker.py     | 2 +-
 lib/bb/ui/uievent.py | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
lib/bb/cooker.py +1 -1
index 2154ef4..08dc1fb 100644
@@ -330,7 +330,7 @@ class BBCooker:
                                 f.write("%s\n" % json.dumps({"class":event.__module__ + "." + event.__class__.__name__, "vars":json.dumps(pickle.dumps(event)) }))
                             except Exception as e:
                                 import traceback
-                                print(e, traceback.format_exc(e))
+                                print(e, traceback.format_exc())
 
 
                     def send(self, event):
lib/bb/ui/uievent.py +1 -1
index ca19166..9542b91 100644
@@ -116,7 +116,7 @@ class BBUIEventQueue:
                 self.server.handle_request()
             except Exception as e:
                 import traceback
-                logger.error("BBUIEventQueue.startCallbackHandler: Exception while trying to handle request: %s\n%s" % (e, traceback.format_exc(e)))
+                logger.error("BBUIEventQueue.startCallbackHandler: Exception while trying to handle request: %s\n%s" % (e, traceback.format_exc()))
 
         self.server.server_close()
 
Signature · 1 line
2.1.4