feat: check mandatories is now centralized
This commit is contained in:
parent
44afe0a367
commit
9cd46c7c10
2 changed files with 38 additions and 1 deletions
|
|
@ -611,3 +611,40 @@ def convert_value(option, value, needs_convert):
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
|
def mandatories(config, errors: list) -> None:
|
||||||
|
try:
|
||||||
|
mandatories = config.value.mandatory()
|
||||||
|
except (ConfigError, PropertiesOptionError, ValueError) as err:
|
||||||
|
try:
|
||||||
|
subconfig = err.subconfig
|
||||||
|
except AttributeError:
|
||||||
|
subconfig = None
|
||||||
|
if subconfig:
|
||||||
|
err.prefix = ""
|
||||||
|
errors.append({str(err): subconfig})
|
||||||
|
else:
|
||||||
|
errors.append(str(err))
|
||||||
|
else:
|
||||||
|
for option in mandatories:
|
||||||
|
_populate_mandatory(option, errors)
|
||||||
|
|
||||||
|
|
||||||
|
def _populate_mandatory(option, errors: list) -> None:
|
||||||
|
try:
|
||||||
|
option.value.get()
|
||||||
|
except PropertiesOptionError as err:
|
||||||
|
if "empty" in err.proptype:
|
||||||
|
msg = _("null is not a valid value for a multi")
|
||||||
|
elif "mandatory" in err.proptype:
|
||||||
|
msg = _("mandatory variable but has no value")
|
||||||
|
else:
|
||||||
|
msg = _("mandatory variable but is inaccessible and has no value or has null in value")
|
||||||
|
else:
|
||||||
|
proptype = option.value.mandatory(return_type=True)
|
||||||
|
if proptype == "empty":
|
||||||
|
msg = _("null is not a valid value for a multi")
|
||||||
|
elif proptype == "mandatory":
|
||||||
|
msg = _("mandatory variable but has no value")
|
||||||
|
errors.append({msg: option._subconfig})
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
["rougail.var1"]
|
[]
|
||||||
Loading…
Reference in a new issue