1
0
Fork 0
mirror of https://github.com/yweber/lodel2.git synced 2025-11-02 04:20:55 +01:00

Added an Exception management for the DatahandlerOption's check_value method

This commit is contained in:
Roland Haroutiounian 2017-02-09 13:57:05 +01:00 committed by prieto
commit 283fa4a3cc

View file

@ -24,6 +24,9 @@ LodelContext.expose_modules(globals(), {
'LodelDataHandlerConsistencyException',
'LodelDataHandlerException'
],
'lodel.validator.validator': [
'ValidationError'
],
'lodel.logger': 'logger'})
@ -78,7 +81,10 @@ class DataHandler(MlNamedObject):
for option_name, option_datas in self.options_spec.items():
if option_name in self.options_values:
# There is a configured option, we check its value
self.options_values[option_name] = option_datas[1].check_value(self.options_values[option_name])
try:
self.options_values[option_name] = option_datas[1].check_value(self.options_values[option_name])
except ValueError:
pass # TODO Deal with the case where the value used for an option has not been validated
else:
# This option was not configured, we get the default value from the specs
self.options_values[option_name] = option_datas[0]
@ -536,4 +542,7 @@ class DatahandlerOption(MlNamedObject):
# @param value
# @return casted value
def check_value(self, value):
return self.__validator(value)
try:
return self.__validator(value)
except ValidationError:
raise ValueError()