summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Madden <jamadden@gmail.com>2018-09-28 10:26:55 -0500
committerJason Madden <jamadden@gmail.com>2018-09-28 10:26:55 -0500
commit268cb192ce7dc3fbbe375bca7f8a62b9af4ac2d6 (patch)
treeba44e75175ec1771fb7fee568ae7208f665faa7f
parent6a7c967c4df0db7ddcc1dcdeb09fbe2ce637d988 (diff)
downloadzope-configuration-268cb192ce7dc3fbbe375bca7f8a62b9af4ac2d6.tar.gz
Include the details also in the invalid default value case too.
-rw-r--r--src/zope/configuration/config.py7
-rw-r--r--src/zope/configuration/tests/test_config.py24
2 files changed, 25 insertions, 6 deletions
diff --git a/src/zope/configuration/config.py b/src/zope/configuration/config.py
index 4b843a9..0123021 100644
--- a/src/zope/configuration/config.py
+++ b/src/zope/configuration/config.py
@@ -1685,15 +1685,16 @@ def toargs(context, schema, data):
try:
args[str(name)] = field.fromUnicode(s)
except ValidationError as v:
- reraise(ConfigurationError("Invalid value for %r: %r" % (n, v)).add_details(v),
+ reraise(ConfigurationError("Invalid value for %r" % (n)).add_details(v),
None, sys.exc_info()[2])
elif field.required:
# if the default is valid, we can use that:
default = field.default
try:
field.validate(default)
- except ValidationError:
- raise ConfigurationError("Missing parameter:", n)
+ except ValidationError as v:
+ reraise(ConfigurationError("Missing parameter: %r" % (n,)).add_details(v),
+ None, sys.exc_info()[2])
args[str(name)] = default
if data:
diff --git a/src/zope/configuration/tests/test_config.py b/src/zope/configuration/tests/test_config.py
index 4a62ea0..f8bebe7 100644
--- a/src/zope/configuration/tests/test_config.py
+++ b/src/zope/configuration/tests/test_config.py
@@ -1789,7 +1789,18 @@ class Test_toargs(unittest.TestCase):
with self.assertRaises(ConfigurationError) as exc:
self._callFUT(context, ISchema, {})
self.assertEqual(exc.exception.args,
- ('Missing parameter:', 'no_default'))
+ ("Missing parameter: 'no_default'",))
+
+ # It includes the details of any validation failure;
+ # The rendering of the nested exception varies by Python version,
+ # sadly.
+ exception_str = str(exc.exception)
+ self.assertTrue(exception_str.startswith(
+ "Missing parameter: 'no_default'\n"
+ ), exception_str)
+ self.assertTrue(exception_str.endswith(
+ "RequiredMissing: no_default"
+ ), exception_str)
def test_w_field_missing_but_default(self):
from zope.interface import Interface
@@ -1810,8 +1821,15 @@ class Test_toargs(unittest.TestCase):
with self.assertRaises(ConfigurationError) as exc:
self._callFUT(context, ISchema, {'count': '-1'})
self.assertEqual(exc.exception.args,
- ("Invalid value for 'count': TooSmall(-1, 0)",))
-
+ ("Invalid value for 'count'",))
+
+ exception_str = str(exc.exception)
+ self.assertTrue(exception_str.startswith(
+ "Invalid value for 'count'\n"
+ ), exception_str)
+ self.assertTrue(exception_str.endswith(
+ "TooSmall: (-1, 0)"
+ ), exception_str)
class Test_expand_action(unittest.TestCase):