From 9cd46c7c10cc7ce17c36be65dea21a3e3561a660 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Sat, 28 Feb 2026 09:18:37 +0100 Subject: [PATCH] feat: check mandatories is now centralized --- src/rougail/user_data.py | 37 +++++++++++++++++++ .../01_6string_empty/makedict/mandatory.json | 2 +- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/rougail/user_data.py b/src/rougail/user_data.py index 30290c533..920af06b5 100644 --- a/src/rougail/user_data.py +++ b/src/rougail/user_data.py @@ -611,3 +611,40 @@ def convert_value(option, value, needs_convert): except: pass 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}) diff --git a/tests/dictionaries/01_6string_empty/makedict/mandatory.json b/tests/dictionaries/01_6string_empty/makedict/mandatory.json index eb57c5bab..0637a088a 100644 --- a/tests/dictionaries/01_6string_empty/makedict/mandatory.json +++ b/tests/dictionaries/01_6string_empty/makedict/mandatory.json @@ -1 +1 @@ -["rougail.var1"] \ No newline at end of file +[] \ No newline at end of file