Skip to contentSkip to conversation

bitbake: Add BBHandledException exception class

PATCH In review Richard Purdie 2 participants 2 messages Jan 9, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bitbake: Add BBHandledException exception class

We have a problem knowing when to show the user debug information and when not to since the code has already shown the user suitable information about why a failure is occurring.

This patch adds a bb.BBHandledException exception class which can be used to identify those exceptions which don't need further explanation to the user.

This patch uses this class for the bb.providers exceptions and ensures the command handling code correctly filters the exceptions meaning that

"bitbake invalid"

now shows an simple error message and not a python traceback.

[YOCTO #1141 partial]

---

bitbake/lib/bb/__init__.py +12 -0
index 5dc959c..e410eea 100644
@@ -27,6 +27,18 @@ import sys
 if sys.version_info < (2, 6, 0):
     raise RuntimeError("Sorry, python 2.6.0 or later is required for this version of bitbake")
 
+
+class BBHandledException(Exception):
+    """
+    The big dillema for generic bitbake code is what information to give the user
+    when an exception occurs. Any exception inheriting this base exception class
+    has already provided information to the user via some 'fired' message type such as
+    an explicitly fired event using bb.fire, or a bb.error message. If bitbake 
+    encounters an expception derived from this class, no backtrace or other information 
+    will be given to the user, its assumed the earlier event provided the relavent information.
+    """
+    pass
+
 import os
 import logging
 
bitbake/lib/bb/command.py +5 -2
index f236dac..2a3a3af 100644
@@ -98,9 +98,12 @@ class Command:
             else:
                 self.finishAsyncCommand("Exited with %s" % arg)
             return False
-        except Exception:
+        except Exception as exc:
             import traceback
-            self.finishAsyncCommand(traceback.format_exc())
+            if isinstance(exc, bb.BBHandledException):
+                self.finishAsyncCommand("")
+            else:
+                self.finishAsyncCommand(traceback.format_exc())
             return False
 
     def finishAsyncCommand(self, msg=None, code=None):
bitbake/lib/bb/providers.py +2 -2
index 4543447..398c8ea 100644
@@ -28,10 +28,10 @@ import bb
 
 logger = logging.getLogger("BitBake.Provider")
 
-class NoProvider(Exception):
+class NoProvider(bb.BBHandledException):
     """Exception raised when no provider of a build dependency can be found"""
 
-class NoRProvider(Exception):
+class NoRProvider(bb.BBHandledException):
     """Exception raised when no provider of a runtime dependency can be found"""
 
 
#1 lore raw

I noticed a typo in the patch below.. Otherwise it looks fine.

Quoted 24 lines · Richard Purdie

We have a problem knowing when to show the user debug information and when not to since the code has already shown the user suitable information about why a failure is occurring.

This patch adds a bb.BBHandledException exception class which can be used to identify those exceptions which don't need further explanation to the user.

This patch uses this class for the bb.providers exceptions and ensures the command handling code correctly filters the exceptions meaning that

"bitbake invalid"

now shows an simple error message and not a python traceback.

[YOCTO #1141 partial]

---

bitbake/lib/bb/__init__.py +0 -0
index 5dc959c..e410eea 100644

bitbake/lib/bb/__init__.py import sys · line 33

Quoted 7 lines
bitbake/lib/bb/__init__.py +4 -0
@@ -27,6 +27,18 @@ import sys
  if sys.version_info<  (2, 6, 0):
      raise RuntimeError("Sorry, python 2.6.0 or later is required for this version of bitbake")
 
+
+class BBHandledException(Exception):
+    """
+    The big dillema for generic bitbake code is what information to give the user

dilemma I think

bitbake/lib/bb/__init__.py import sys · line 37

Quoted 4 lines
bitbake/lib/bb/__init__.py +4 -0
+    when an exception occurs. Any exception inheriting this base exception class
+    has already provided information to the user via some 'fired' message type such as
+    an explicitly fired event using bb.fire, or a bb.error message. If bitbake
+    encounters an expception derived from this class, no backtrace or other information

exception

bitbake/lib/bb/__init__.py import sys · line 38

Quoted 1 line
bitbake/lib/bb/__init__.py +1 -0
+    will be given to the user, its assumed the earlier event provided the relavent information.

relevant

Quoted 49 lines
bitbake/lib/bb/__init__.py +3 -0
+    """
+    pass
+
  import os
  import logging
 
bitbake/lib/bb/command.py +5 -2
index f236dac..2a3a3af 100644
@@ -98,9 +98,12 @@ class Command:
              else:
                  self.finishAsyncCommand("Exited with %s" % arg)
              return False
-        except Exception:
+        except Exception as exc:
              import traceback
-            self.finishAsyncCommand(traceback.format_exc())
+            if isinstance(exc, bb.BBHandledException):
+                self.finishAsyncCommand("")
+            else:
+                self.finishAsyncCommand(traceback.format_exc())
              return False
 
      def finishAsyncCommand(self, msg=None, code=None):
bitbake/lib/bb/providers.py +2 -2
index 4543447..398c8ea 100644
@@ -28,10 +28,10 @@ import bb
 
  logger = logging.getLogger("BitBake.Provider")
 
-class NoProvider(Exception):
+class NoProvider(bb.BBHandledException):
      """Exception raised when no provider of a build dependency can be found"""
 
-class NoRProvider(Exception):
+class NoRProvider(bb.BBHandledException):
      """Exception raised when no provider of a runtime dependency can be found"""
 
 

_______________________________________________
bitbake-devel mailing list
[email protected]
http://lists.linuxtogo.org/cgi-bin/mailman/listinfo/bitbake-devel