From 86809acb61386a68de94b309fb7f0e5959e167c9 Mon Sep 17 00:00:00 2001 From: Randall Burt Date: Thu, 28 Aug 2014 12:17:47 -0500 Subject: [PATCH] Error class can accept message with format characters Since the Error class is designed to simply accept any message string, treating the message text as a format string causes errors if the error message has format characters. This changes Error to have its own format string that just echos the passed in message. Change-Id: I1161d5e177dff860e180f845405d536e18222b23 Closes-Bug: 1361471 --- heat/common/exception.py | 7 ++++--- heat/tests/test_exception.py | 6 ++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/heat/common/exception.py b/heat/common/exception.py index f2533a856..b007e7472 100644 --- a/heat/common/exception.py +++ b/heat/common/exception.py @@ -324,9 +324,10 @@ class EgressRuleNotAllowed(HeatException): class Error(HeatException): - def __init__(self, msg_fmt): - self.msg_fmt = msg_fmt - super(Error, self).__init__() + msg_fmt = "%(message)s" + + def __init__(self, msg): + super(Error, self).__init__(message=msg) class NotFound(HeatException): diff --git a/heat/tests/test_exception.py b/heat/tests/test_exception.py index f15b5b3a2..e6d5cf553 100644 --- a/heat/tests/test_exception.py +++ b/heat/tests/test_exception.py @@ -16,6 +16,7 @@ import fixtures +import six from heat.common import exception from heat.tests import common @@ -32,3 +33,8 @@ class TestHeatException(common.HeatTestCase): 'heat.common.exception._FATAL_EXCEPTION_FORMAT_ERRORS', True)) self.assertRaises(KeyError, TestException) + + def test_format_string_error_message(self): + message = "This format %(message)s should work" + err = exception.Error(message) + self.assertEqual(message, six.text_type(err))