VMM/cli/config: CliConfig.set raise a ConfigError, if the new v0.6.x
authorPascal Volk <neverseen@users.sourceforge.net>
Fri, 06 Aug 2010 06:14:04 +0000
branchv0.6.x
changeset 344 0d2430dc6ef8
parent 343 9232ed7e4d85
child 345 f8d5c8bb8bce
VMM/cli/config: CliConfig.set raise a ConfigError, if the new value could not be set.
VirtualMailManager/cli/config.py
--- a/VirtualMailManager/cli/config.py	Fri Aug 06 03:45:34 2010 +0000
+++ b/VirtualMailManager/cli/config.py	Fri Aug 06 06:14:04 2010 +0000
@@ -15,7 +15,7 @@
 from VirtualMailManager.config import Config, ConfigValueError, LazyConfig
 from VirtualMailManager.errors import ConfigError
 from VirtualMailManager.cli import w_err, w_std
-from VirtualMailManager.constants import VMM_TOO_MANY_FAILURES
+from VirtualMailManager.constants import CONF_ERROR, VMM_TOO_MANY_FAILURES
 
 _ = lambda msg: msg
 
@@ -65,12 +65,15 @@
         If the new `value` has been set, the configuration file will be
         immediately updated.
 
-        Throws a ``ValueError`` if `value` couldn't be converted to
-        ``LazyConfigOption.cls``"""
+        Throws a ``ConfigError`` if `value` couldn't be converted to
+        ``LazyConfigOption.cls`` or ``LazyConfigOption.validate`` fails."""
         section, option_ = self._get_section_option(option)
-        val = self._cfg[section][option_].cls(value)
-        if self._cfg[section][option_].validate:
-            val = self._cfg[section][option_].validate(val)
+        try:
+            val = self._cfg[section][option_].cls(value)
+            if self._cfg[section][option_].validate:
+                val = self._cfg[section][option_].validate(val)
+        except (ValueError, ConfigValueError), err:
+            raise ConfigError(str(err), CONF_ERROR)
         # Do not write default values also skip identical values
         if not self._cfg[section][option_].default is None:
             old_val = self.dget(option)