ConfigParser exeption message should be returned
When we fail to parse config file it would be good to know why instead of having a generic message. When we print the exception, the message is pretty clear. Related: https://bugzilla.redhat.com/show_bug.cgi?id=1950544 Change-Id: I59ebd9e52b6fb6ab53ec9e53529d2feadc9e745e
This commit is contained in:
parent
2470d54bbd
commit
a38d34dd82
@ -60,8 +60,10 @@ def get_result(path, section, key, default=None):
|
||||
|
||||
try:
|
||||
config.read(path)
|
||||
except (OSError, ConfigParser.ParsingError):
|
||||
msg = "The file '{}' is not in a valid INI format.".format(path)
|
||||
except (OSError, ConfigParser.ParsingError) as exc_msg:
|
||||
msg = "The file '{}' is not in a valid INI format: {}".format(
|
||||
path, exc_msg
|
||||
)
|
||||
ret = ReturnValue.INVALID_FORMAT
|
||||
return (ret, msg, value)
|
||||
|
||||
|
@ -82,8 +82,11 @@ class TestValidationsReadIni(base.TestCase):
|
||||
tmpfile.close()
|
||||
|
||||
self.assertEqual(validation.ReturnValue.INVALID_FORMAT, ret)
|
||||
self.assertEqual("The file '{}' is not in a valid INI format.".format(
|
||||
tmp_name), msg)
|
||||
asserted = ("The file '{path}' is not in a valid INI format: File "
|
||||
"contains no section headers.\nfile: '{path}', line: 2\n"
|
||||
"'[DEFAULT#\\n\'").format(path=tmp_name)
|
||||
|
||||
self.assertEqual(asserted, msg)
|
||||
self.assertIsNone(value)
|
||||
|
||||
def test_get_result_key_not_found(self):
|
||||
|
Loading…
Reference in New Issue
Block a user