From: Michael Goldish Subject: [KVM-AUTOTEST PATCH 4/7] [RFC] Embed context information in exception strings Date: Mon, 3 Jan 2011 20:34:08 +0200 Message-ID: <1294079651-21631-4-git-send-email-mgoldish@redhat.com> References: <1294079651-21631-1-git-send-email-mgoldish@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: autotest@test.kernel.org, kvm@vger.kernel.org Return-path: In-Reply-To: <1294079651-21631-1-git-send-email-mgoldish@redhat.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: autotest-bounces@test.kernel.org Errors-To: autotest-bounces@test.kernel.org List-Id: kvm.vger.kernel.org Exceptions look for a .context attribute and embed it in the string returned by __str__(). If the attribute isn't set (or if it's an empty strgin) nothing is embedded. Signed-off-by: Michael Goldish --- client/common_lib/error.py | 13 ++++++++++++- 1 files changed, 12 insertions(+), 1 deletions(-) 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 -- 1.7.3.4