feat: return index in error message

This commit is contained in:
egarette@silique.fr 2025-01-04 17:39:11 +01:00
parent 42471d42b7
commit 4cba819e0a
6 changed files with 104 additions and 87 deletions

View file

@ -2,7 +2,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Tiramisu\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-11-25 08:23+0100\n"
"POT-Creation-Date: 2024-12-15 11:03+0100\n"
"PO-Revision-Date: \n"
"Last-Translator: Emmanuel Garette <egarette@cadoles.com>\n"
"Language-Team: Tiramisu's team <egarette@cadoles.com>\n"
@ -34,23 +34,23 @@ msgstr "Ne peut avoir de warnings durant une validation"
msgid "Commands:"
msgstr "Commandes :"
#: tiramisu/api.py:111 tiramisu/api.py:1840
#: tiramisu/api.py:111 tiramisu/api.py:1843
msgid "please specify a valid sub function ({0}.{1})"
msgstr "veuillez spécifier une sous fonction valide ({0}.{1})"
#: tiramisu/api.py:194
#: tiramisu/api.py:196
msgid "please do not specify index ({0}.{1})"
msgstr "veuillez ne pas spécifier d'index ({0}.{1})"
#: tiramisu/api.py:199 tiramisu/api.py:844
#: tiramisu/api.py:201 tiramisu/api.py:847
msgid "please specify index with a follower option ({0}.{1})"
msgstr "veuillez spécifier un index avec une option suiveuse ({0}.{1})"
#: tiramisu/api.py:220
#: tiramisu/api.py:222
msgid "please specify a valid sub function ({0}.{1}): {2}"
msgstr "veuillez spécifier une sous fonction valide ({0}.{1}): {2}"
#: tiramisu/api.py:431
#: tiramisu/api.py:434
msgid ""
"the option {0} is not a dynamic option, cannot get identifiers with "
"only_self parameter to True"
@ -58,15 +58,15 @@ msgstr ""
"l'option {0} n'est pas une option dynamique, ne peut retrouver l'identifiant "
"avec le paramètre only_self à True"
#: tiramisu/api.py:517
#: tiramisu/api.py:520
msgid "cannot get option from a follower symlink without index"
msgstr "ne peut avoir d'option pour une symlink suiveuse sans index"
#: tiramisu/api.py:592
#: tiramisu/api.py:595
msgid "cannot add this property: \"{0}\""
msgstr "ne peut pas ajouter cette propriété : \"{0}\""
#: tiramisu/api.py:619
#: tiramisu/api.py:622
msgid ""
"cannot remove option's property \"{0}\", use permissive instead in option "
"\"{1}\""
@ -74,11 +74,11 @@ msgstr ""
"ne supprimer la propriété \"{0}\" de l'option, utiliser plutôt permissive "
"dans l'option \"{1}\""
#: tiramisu/api.py:623
#: tiramisu/api.py:626
msgid "cannot find \"{0}\" in option \"{1}\""
msgstr "ne peut trouver \"{0}\" dans l'option \"{1}\""
#: tiramisu/api.py:628
#: tiramisu/api.py:631
msgid ""
"cannot remove option's property \"{0}\", use permissive instead in option "
"\"{1}\" at index \"{2}\""
@ -86,39 +86,39 @@ msgstr ""
"ne peut supprimer la propriété \"{0}\" de l'option, utilisez plutôt "
"permissive dans l'option \"{1}\" a l'index \"{2}\""
#: tiramisu/api.py:632
#: tiramisu/api.py:635
msgid "cannot find \"{0}\" in option \"{1}\" at index \"{2}\""
msgstr "ne peut trouver \"{0}\" dans l'option \"{1}\" à l'index \"{2}\""
#: tiramisu/api.py:676
#: tiramisu/api.py:679
msgid "cannot find \"{0}\""
msgstr "ne peut trouver \"{0}\""
#: tiramisu/api.py:808
#: tiramisu/api.py:811
msgid "cannot reduce length of the leader {}"
msgstr "il est impossible de réduire la longueur du leader \"{}\""
#: tiramisu/api.py:861
#: tiramisu/api.py:864
msgid "only multi value has defaultmulti"
msgstr "seule les valeurs multiple a l'attribut defaultmulti"
#: tiramisu/api.py:1020
#: tiramisu/api.py:1023
msgid "please specify a valid sub function ({0}.{1}) for {2}"
msgstr "veuillez spécifier une sous fonction valide ({0}.{1}) pour {2}"
#: tiramisu/api.py:1407
#: tiramisu/api.py:1410
msgid "properties must be a frozenset"
msgstr "une propriété doit être de type frozenset"
#: tiramisu/api.py:1411 tiramisu/api.py:1438
#: tiramisu/api.py:1414 tiramisu/api.py:1441
msgid "unknown when {} (must be in append or remove)"
msgstr "value {} inconsistent (doit être append ou remove)"
#: tiramisu/api.py:1424 tiramisu/api.py:1448 tiramisu/config.py:1681
#: tiramisu/api.py:1427 tiramisu/api.py:1451 tiramisu/config.py:1681
msgid "unknown type {}"
msgstr "type inconnu {}"
#: tiramisu/api.py:1812
#: tiramisu/api.py:1815
msgid "do not use unrestraint, nowarnings or forcepermissive together"
msgstr ""
"il ne faut pas utiliser unrestraint, nowarnings ou forcepermissive ensemble"
@ -205,14 +205,14 @@ msgstr ""
"l'option {0} n'est pas une dynoptiondescription ou n'est pas dans une "
"dynoptiondescription"
#: tiramisu/autolib.py:682
#: tiramisu/autolib.py:685
msgid ""
"cannot calculate arguments for \"{0}\", cannot find dynamic variable \"{1}\""
msgstr ""
"impossible de calculer les arguments de \"{0}\", la variable dynamic \"{1}\" "
"ne peut être trouvée"
#: tiramisu/autolib.py:861
#: tiramisu/autolib.py:864
msgid ""
"the \"{}\" function with positional arguments \"{}\" and keyword arguments "
"\"{}\" must not return a list (\"{}\") for the follower option {}"
@ -221,7 +221,7 @@ msgstr ""
"nommés \"{}\" ne doit pas retourner une liste (\"{}\") pour l'option "
"suiveuse {}"
#: tiramisu/autolib.py:876
#: tiramisu/autolib.py:879
msgid ""
"the \"{}\" function must not return a list (\"{}\") for the follower option "
"{}"
@ -229,7 +229,7 @@ msgstr ""
"la fonction \"{}\" ne doit pas retourner une liste (\"{}\") pour l'option "
"suiveuse {}"
#: tiramisu/autolib.py:917
#: tiramisu/autolib.py:920
msgid ""
"unexpected error \"{0}\" in function \"{1}\" with arguments \"{3}\" and "
"\"{4}\" for option {2}"
@ -237,7 +237,7 @@ msgstr ""
"erreur inattendue \"{0}\" dans la fonction \"{1}\" avec les arguments "
"\"{3}\" et \"{4}\" pour l'option {2}"
#: tiramisu/autolib.py:928
#: tiramisu/autolib.py:931
msgid "unexpected error \"{0}\" in function \"{1}\" for option {2}"
msgstr "erreur inattendue \"{0}\" dans la fonction \"{1}\" pour l'option {2}"
@ -603,9 +603,17 @@ msgstr ""
msgid "must starts with \"/\""
msgstr "doit débuter par \"/\""
#: tiramisu/option/filenameoption.py:78
msgid "cannot find {0} \"{1}\""
msgstr "ne peut pas trouver {0} \"{1}\""
#: tiramisu/option/filenameoption.py:77
msgid "directory"
msgstr "répertoire"
#: tiramisu/option/filenameoption.py:77
msgid "file"
msgstr "fichier"
#: tiramisu/option/filenameoption.py:79
msgid "cannot find this {0}"
msgstr "ce {0} est introuvable"
#: tiramisu/option/intoption.py:52
msgid "value should be equal or greater than \"{0}\""
@ -961,6 +969,9 @@ msgstr ""
msgid "information's item not found \"{}\""
msgstr "l'information de l'objet ne sont pas trouvé \"{}\""
#~ msgid "cannot find {0} \"{1}\""
#~ msgstr "ne peut pas trouver {0} \"{1}\""
#~ msgid ""
#~ "IP \"{ip[\"value\"]}\" ({ip[\"name\"]}) with this netmask is in fact a "
#~ "broacast address"
@ -1140,9 +1151,6 @@ msgstr "l'information de l'objet ne sont pas trouvé \"{}\""
#~ msgid "email address"
#~ msgstr "adresse mail"
#~ msgid "file name"
#~ msgstr "nom de fichier"
#~ msgid "float"
#~ msgstr "nombre flottant"

View file

@ -5,7 +5,7 @@
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2024-11-25 08:29+0100\n"
"POT-Creation-Date: 2024-12-15 11:06+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -35,79 +35,79 @@ msgstr ""
msgid "Commands:"
msgstr ""
#: tiramisu/api.py:111 tiramisu/api.py:1840
#: tiramisu/api.py:111 tiramisu/api.py:1843
msgid "please specify a valid sub function ({0}.{1})"
msgstr ""
#: tiramisu/api.py:194
#: tiramisu/api.py:196
msgid "please do not specify index ({0}.{1})"
msgstr ""
#: tiramisu/api.py:199 tiramisu/api.py:844
#: tiramisu/api.py:201 tiramisu/api.py:847
msgid "please specify index with a follower option ({0}.{1})"
msgstr ""
#: tiramisu/api.py:220
#: tiramisu/api.py:222
msgid "please specify a valid sub function ({0}.{1}): {2}"
msgstr ""
#: tiramisu/api.py:431
#: tiramisu/api.py:434
msgid "the option {0} is not a dynamic option, cannot get identifiers with only_self parameter to True"
msgstr ""
#: tiramisu/api.py:517
#: tiramisu/api.py:520
msgid "cannot get option from a follower symlink without index"
msgstr ""
#: tiramisu/api.py:592
#: tiramisu/api.py:595
msgid "cannot add this property: \"{0}\""
msgstr ""
#: tiramisu/api.py:619
#: tiramisu/api.py:622
msgid "cannot remove option's property \"{0}\", use permissive instead in option \"{1}\""
msgstr ""
#: tiramisu/api.py:623
#: tiramisu/api.py:626
msgid "cannot find \"{0}\" in option \"{1}\""
msgstr ""
#: tiramisu/api.py:628
#: tiramisu/api.py:631
msgid "cannot remove option's property \"{0}\", use permissive instead in option \"{1}\" at index \"{2}\""
msgstr ""
#: tiramisu/api.py:632
#: tiramisu/api.py:635
msgid "cannot find \"{0}\" in option \"{1}\" at index \"{2}\""
msgstr ""
#: tiramisu/api.py:676
#: tiramisu/api.py:679
msgid "cannot find \"{0}\""
msgstr ""
#: tiramisu/api.py:808
#: tiramisu/api.py:811
msgid "cannot reduce length of the leader {}"
msgstr ""
#: tiramisu/api.py:861
#: tiramisu/api.py:864
msgid "only multi value has defaultmulti"
msgstr ""
#: tiramisu/api.py:1020
#: tiramisu/api.py:1023
msgid "please specify a valid sub function ({0}.{1}) for {2}"
msgstr ""
#: tiramisu/api.py:1407
#: tiramisu/api.py:1410
msgid "properties must be a frozenset"
msgstr ""
#: tiramisu/api.py:1411 tiramisu/api.py:1438
#: tiramisu/api.py:1414 tiramisu/api.py:1441
msgid "unknown when {} (must be in append or remove)"
msgstr ""
#: tiramisu/api.py:1424 tiramisu/api.py:1448 tiramisu/config.py:1681
#: tiramisu/api.py:1427 tiramisu/api.py:1451 tiramisu/config.py:1681
msgid "unknown type {}"
msgstr ""
#: tiramisu/api.py:1812
#: tiramisu/api.py:1815
msgid "do not use unrestraint, nowarnings or forcepermissive together"
msgstr ""
@ -187,23 +187,23 @@ msgstr ""
msgid "option {0} is not a dynoptiondescription or in a dynoptiondescription"
msgstr ""
#: tiramisu/autolib.py:682
#: tiramisu/autolib.py:685
msgid "cannot calculate arguments for \"{0}\", cannot find dynamic variable \"{1}\""
msgstr ""
#: tiramisu/autolib.py:861
#: tiramisu/autolib.py:864
msgid "the \"{}\" function with positional arguments \"{}\" and keyword arguments \"{}\" must not return a list (\"{}\") for the follower option {}"
msgstr ""
#: tiramisu/autolib.py:876
#: tiramisu/autolib.py:879
msgid "the \"{}\" function must not return a list (\"{}\") for the follower option {}"
msgstr ""
#: tiramisu/autolib.py:917
#: tiramisu/autolib.py:920
msgid "unexpected error \"{0}\" in function \"{1}\" with arguments \"{3}\" and \"{4}\" for option {2}"
msgstr ""
#: tiramisu/autolib.py:928
#: tiramisu/autolib.py:931
msgid "unexpected error \"{0}\" in function \"{1}\" for option {2}"
msgstr ""
@ -520,8 +520,16 @@ msgstr ""
msgid "must starts with \"/\""
msgstr ""
#: tiramisu/option/filenameoption.py:78
msgid "cannot find {0} \"{1}\""
#: tiramisu/option/filenameoption.py:77
msgid "directory"
msgstr ""
#: tiramisu/option/filenameoption.py:77
msgid "file"
msgstr ""
#: tiramisu/option/filenameoption.py:79
msgid "cannot find this {0}"
msgstr ""
#: tiramisu/option/intoption.py:52

View file

@ -909,7 +909,7 @@ def calculate(
except (ValueError, ValueWarning) as err:
if allow_value_error:
if force_value_warning:
raise ValueWarning(str(err))
raise ValueWarning(msg=str(err))
raise err from err
error = err
except ConfigError as err:

View file

@ -181,7 +181,7 @@ class _CommonError:
try:
msg = self.prefix
except AttributeError:
self.prefix = self.tmpl.format(self.val, _(self.display_type), self.name)
self.prefix = self.tmpl.format(self.val, _(self.display_type), self.name, self.index)
msg = self.prefix
if self.err_msg:
if msg:
@ -196,13 +196,16 @@ class _CommonError:
class ValueWarning(_CommonError, UserWarning):
tmpl = None
def __init__(self, *args, **kwargs):
def __init__(self, **kwargs):
if ValueWarning.tmpl is None:
if kwargs.get('index') is None:
ValueWarning.tmpl = _('attention, "{0}" could be an invalid {1} for "{2}"')
if len(args) == 1 and not kwargs:
self.msg = args[0]
else:
super().__init__(*args, **kwargs)
ValueWarning.tmpl = _('attention, "{0}" could be an invalid {1} for "{2}" at index "{3}"')
if list(kwargs) == ['msg']:
self.msg = kwargs['msg']
else:
super().__init__(**kwargs)
self.msg = None
def __str__(self):
@ -214,10 +217,13 @@ class ValueWarning(_CommonError, UserWarning):
class ValueOptionError(_CommonError, ValueError):
tmpl = None
def __init__(self, *args, **kwargs):
def __init__(self, **kwargs):
if ValueOptionError.tmpl is None:
if kwargs.get('index') is None:
ValueOptionError.tmpl = _('"{0}" is an invalid {1} for "{2}"')
super().__init__(*args, **kwargs)
else:
ValueOptionError.tmpl = _('"{0}" is an invalid {1} for "{2}" at index "{3}"')
super().__init__(**kwargs)
class ValueErrorWarning(ValueWarning):

View file

@ -127,11 +127,6 @@ class Option(BaseOption):
def test_multi_value(value):
if isinstance(value, Calculation):
return
# option_bag = OptionBag(self,
# None,
# undefined,
# properties=None,
# )
try:
self.validate(value)
self.validate_with_option(
@ -329,12 +324,12 @@ class Option(BaseOption):
except ValueWarning as warn:
warnings.warn_explicit(
ValueWarning(
subconfig,
val,
_(self.get_type()),
self,
str(warn),
_index,
subconfig=subconfig,
val=val,
display_type=_(self.get_type()),
opt=self,
err_msg=str(warn),
index=_index,
),
ValueWarning,
self.__class__.__name__,
@ -370,12 +365,12 @@ class Option(BaseOption):
if is_warnings_only:
warnings.warn_explicit(
ValueWarning(
subconfig,
_value,
_(self.get_type()),
self,
str(err),
_index,
subconfig=subconfig,
val=_value,
display_type=_(self.get_type()),
opt=self,
err_msg=str(err),
index=_index,
),
ValueWarning,
self.__class__.__name__,
@ -442,11 +437,11 @@ class Option(BaseOption):
or "demoting_error_warning" not in subconfig.config_bag.properties
):
raise ValueOptionError(
subconfig, val, _(self.get_type()), self, str(err), err_index
subconfig=subconfig, val=val, display_type=_(self.get_type()), opt=self, err_msg=str(err), index=err_index
) from err
warnings.warn_explicit(
ValueErrorWarning(
subconfig, val, _(self.get_type()), self, str(err), err_index
subconfig=subconfig, val=val, display_type=_(self.get_type()), opt=self, err_msg=str(err), index=err_index
),
ValueErrorWarning,
self.__class__.__name__,