diff mbox

[KVM-AUTOTEST,4/7,RFC] Embed context information in exception strings

Message ID 1294079651-21631-4-git-send-email-mgoldish@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Michael Goldish Jan. 3, 2011, 6:34 p.m. UTC
None
diff mbox

Patch

diff --git a/client/common_lib/error.py b/client/common_lib/error.py
index 394f555..ed7132e 100644
--- a/client/common_lib/error.py
+++ b/client/common_lib/error.py
@@ -111,7 +111,14 @@  class JobComplete(SystemExit):
 
 class AutotestError(Exception):
     """The parent of all errors deliberatly thrown within the client code."""
-    pass
+    def context_str(self):
+        if hasattr(self, "context") and self.context:
+            return "    [context: %s]" % self.context
+        else:
+            return ""
+
+    def __str__(self):
+        return Exception.__str__(self) + self.context_str()
 
 
 class JobError(AutotestError):
@@ -133,6 +140,7 @@  class UnhandledJobError(JobError):
             msg = "Unhandled %s: %s"
             msg %= (self.unhandled_exception.__class__.__name__,
                     self.unhandled_exception)
+            msg += self.context_str()
             msg += "\n" + self.traceback
             return msg
 
@@ -179,6 +187,7 @@  class UnhandledTestError(TestError):
             msg = "Unhandled %s: %s"
             msg %= (self.unhandled_exception.__class__.__name__,
                     self.unhandled_exception)
+            msg += self.context_str()
             msg += "\n" + self.traceback
             return msg
 
@@ -197,6 +206,7 @@  class UnhandledTestFail(TestFail):
             msg = "Unhandled %s: %s"
             msg %= (self.unhandled_exception.__class__.__name__,
                     self.unhandled_exception)
+            msg += self.context_str()
             msg += "\n" + self.traceback
             return msg
 
@@ -221,6 +231,7 @@  class CmdError(TestError):
 
         if self.additional_text:
             msg += ", " + self.additional_text
+        msg += self.context_str()
         msg += '\n' + repr(self.result_obj)
         return msg