From: Michael Goldish Subject: [KVM-AUTOTEST PATCH v2 4/6] [RFC] Embed context information in exception strings Date: Wed, 5 Jan 2011 17:45:27 +0200 Message-ID: <1294242329-11034-4-git-send-email-mgoldish@redhat.com> References: <1294242329-11034-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: <1294242329-11034-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 string) nothing is embedded. Signed-off-by: Michael Goldish --- client/common_lib/error.py | 10 +++++++++- 1 files changed, 9 insertions(+), 1 deletions(-) diff --git a/client/common_lib/error.py b/client/common_lib/error.py index 952f977..ff22d84 100644 --- a/client/common_lib/error.py +++ b/client/common_lib/error.py @@ -126,7 +126,8 @@ class JobComplete(SystemExit): class AutotestError(Exception): """The parent of all errors deliberatly thrown within the client code.""" - pass + def __str__(self): + return Exception.__str__(self) + _context_message(self) class JobError(AutotestError): @@ -148,6 +149,8 @@ class UnhandledJobError(JobError): msg = "Unhandled %s: %s" msg %= (self.unhandled_exception.__class__.__name__, self.unhandled_exception) + if not isinstance(self.unhandled_exception, AutotestError): + msg += _context_message(self.unhandled_exception) msg += "\n" + self.traceback return msg @@ -194,6 +197,8 @@ class UnhandledTestError(TestError): msg = "Unhandled %s: %s" msg %= (self.unhandled_exception.__class__.__name__, self.unhandled_exception) + if not isinstance(self.unhandled_exception, AutotestError): + msg += _context_message(self.unhandled_exception) msg += "\n" + self.traceback return msg @@ -212,6 +217,8 @@ class UnhandledTestFail(TestFail): msg = "Unhandled %s: %s" msg %= (self.unhandled_exception.__class__.__name__, self.unhandled_exception) + if not isinstance(self.unhandled_exception, AutotestError): + msg += _context_message(self.unhandled_exception) msg += "\n" + self.traceback return msg @@ -236,6 +243,7 @@ class CmdError(TestError): if self.additional_text: msg += ", " + self.additional_text + msg += _context_message(self) msg += '\n' + repr(self.result_obj) return msg -- 1.7.3.4