Преглед на файлове

bb.exceptions: add to_string convenience function

Signed-off-by: Chris Larson <chris_larson@mentor.com>
Chris Larson преди 13 години
родител
ревизия
17a64df7e9
променени са 1 файла, в които са добавени 6 реда и са изтрити 0 реда
  1. 6 0
      lib/bb/exceptions.py

+ 6 - 0
lib/bb/exceptions.py

@@ -53,3 +53,9 @@ def format_exception(etype, value, tb, context=1, limit=None, formatter=None):
     formatted.extend(format_extracted(tb, formatter, limit))
     formatted.extend(traceback.format_exception_only(etype, value))
     return formatted
+
+def to_string(exc):
+    if isinstance(exc, SystemExit):
+        if not isinstance(exc.code, basestring):
+            return 'Exited with "%d"' % exc.code
+    return str(exc)