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
This commit is contained in:
Randall Burt 2014-08-28 12:17:47 -05:00
parent f96cecfa4b
commit 86809acb61
2 changed files with 10 additions and 3 deletions

View File

@ -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):

View File

@ -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))