From a38d34dd82c52cc46a9911813c26b5e4671a1e0c Mon Sep 17 00:00:00 2001
From: David Vallee Delisle <dvd@redhat.com>
Date: Mon, 26 Apr 2021 22:01:34 -0400
Subject: [PATCH] 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
---
 validations_common/library/validations_read_ini.py         | 6 ++++--
 .../tests/library/test_validations_read_ini.py             | 7 +++++--
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/validations_common/library/validations_read_ini.py b/validations_common/library/validations_read_ini.py
index 5e4e3ec..b44002c 100644
--- a/validations_common/library/validations_read_ini.py
+++ b/validations_common/library/validations_read_ini.py
@@ -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)
 
diff --git a/validations_common/tests/library/test_validations_read_ini.py b/validations_common/tests/library/test_validations_read_ini.py
index 09875c9..4bf2237 100644
--- a/validations_common/tests/library/test_validations_read_ini.py
+++ b/validations_common/tests/library/test_validations_read_ini.py
@@ -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):