Browse Source

bb.exceptions: handle tb entries without context

Signed-off-by: Chris Larson <chris_larson@mentor.com>
Chris Larson 13 years ago
parent
commit
b010c4d37c
1 changed files with 5 additions and 2 deletions
  1. 5 2
      lib/bb/exceptions.py

+ 5 - 2
lib/bb/exceptions.py

@@ -8,10 +8,13 @@ from collections import namedtuple
 class TracebackEntry(namedtuple.abc):
     """Pickleable representation of a traceback entry"""
     _fields = 'filename lineno function args code_context index'
-    _header = '  File "{0.filename}", line {0.lineno}, in {0.function}{0.args}:\n'
+    _header = '  File "{0.filename}", line {0.lineno}, in {0.function}{0.args}'
 
     def format(self, formatter=None):
-        formatted = [self._header.format(self)]
+        if not self.code_context:
+            return self._header.format(self) + '\n'
+
+        formatted = [self._header.format(self) + ':\n']
 
         for lineindex, line in enumerate(self.code_context):
             if formatter: