From db82dd6d41fbc9ea5a9e1b48aae8a2c5951a7533 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Wed, 9 Apr 2025 08:27:38 +0200 Subject: [PATCH] fix: better error message --- locale/fr/LC_MESSAGES/tiramisu.po | 48 +++++++++++---------- locale/tiramisu.pot | 28 ++++++------ tests/test_config.py | 4 +- tiramisu/locale/fr/LC_MESSAGES/tiramisu.mo | Bin 27045 -> 26783 bytes tiramisu/option/dynoptiondescription.py | 2 +- tiramisu/option/optiondescription.py | 22 ++++++---- 6 files changed, 53 insertions(+), 51 deletions(-) diff --git a/locale/fr/LC_MESSAGES/tiramisu.po b/locale/fr/LC_MESSAGES/tiramisu.po index f5ac667..dfe63cd 100644 --- a/locale/fr/LC_MESSAGES/tiramisu.po +++ b/locale/fr/LC_MESSAGES/tiramisu.po @@ -2,7 +2,7 @@ msgid "" msgstr "" "Project-Id-Version: Tiramisu\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2025-03-19 09:51+0100\n" +"POT-Creation-Date: 2025-04-09 08:14+0200\n" "PO-Revision-Date: \n" "Last-Translator: Emmanuel Garette \n" "Language-Team: Tiramisu's team \n" @@ -90,7 +90,7 @@ msgstr "" 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:679 +#: tiramisu/api.py:679 tiramisu/option/optiondescription.py:283 msgid "cannot find \"{0}\"" msgstr "ne peut trouver \"{0}\"" @@ -619,7 +619,7 @@ msgstr "ne doit pas être une IP" msgid "some characters are uppercase" msgstr "des caractères sont en majuscule" -#: tiramisu/option/dynoptiondescription.py:131 +#: tiramisu/option/dynoptiondescription.py:130 msgid "DynOptionDescription identifiers for option {0}, is not a list ({1})" msgstr "" "les identifiants de la DynOptionDescription pour l'option {0}, n'est pas une " @@ -806,41 +806,34 @@ msgstr "lequel \"{}\" doit être une liste de liste" msgid "duplicate option: {0}" msgstr "option dupliquée : {0}" -#: tiramisu/option/optiondescription.py:244 -msgid "" -"unknown option \"{0}\" in root optiondescription (it's a dynamic option)" -msgstr "" -"option \"{0}\" inconnue dans l'optiondescription racine (c'est une option " -"dynamique)" +#: tiramisu/option/optiondescription.py:249 +msgid "cannot access to \"{0}\" it's a dynamic option" +msgstr "ne peut accéder à \"{0}\" c'est une option dynamique" -#: tiramisu/option/optiondescription.py:279 -msgid "unknown option \"{0}\" in root optiondescription" -msgstr "option \"{0}\" inconnue dans l'optiondescription racine" +#: tiramisu/option/optiondescription.py:286 +msgid "cannot find \"{0}\" in \"{1}\"" +msgstr "ne peut pas trouver \"{0}\" dans \"{1}\"" -#: tiramisu/option/optiondescription.py:282 -msgid "unknown option \"{0}\" in optiondescription {1}" -msgstr "option \"{0}\" inconnue dans l'optiondescription {1}" - -#: tiramisu/option/optiondescription.py:338 +#: tiramisu/option/optiondescription.py:342 msgid "children in optiondescription \"{}\" must be a list" msgstr "les enfants d'une optiondescription \"{}\" doivent être une liste" -#: tiramisu/option/optiondescription.py:366 +#: tiramisu/option/optiondescription.py:370 msgid "duplicate option name: \"{0}\"" msgstr "nom de l'option dupliqué : \"{0}\"" -#: tiramisu/option/optiondescription.py:372 +#: tiramisu/option/optiondescription.py:376 msgid "" "the option's name \"{0}\" start as the dynoptiondescription's name \"{1}\"" msgstr "" "le nom de l'option \"{0}\" commence comme le nom du dynoptiondescription " "\"{1}\"" -#: tiramisu/option/optiondescription.py:415 +#: tiramisu/option/optiondescription.py:419 msgid "cannot change group_type if already set (old {0}, new {1})" msgstr "ne peut changer group_type si déjà spécifié (ancien {0}, nouveau {1})" -#: tiramisu/option/optiondescription.py:420 +#: tiramisu/option/optiondescription.py:424 msgid "group_type: {0} not allowed" msgstr "group_type : {0} non autorisé" @@ -1028,8 +1021,17 @@ 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 "" +#~ "unknown option \"{0}\" in root optiondescription (it's a dynamic option)" +#~ msgstr "" +#~ "option \"{0}\" inconnue dans l'optiondescription racine (c'est une option " +#~ "dynamique)" + +#~ msgid "unknown option \"{0}\" in root optiondescription" +#~ msgstr "option \"{0}\" inconnue dans l'optiondescription racine" + +#~ msgid "unknown option \"{0}\" in optiondescription {1}" +#~ msgstr "option \"{0}\" inconnue dans l'optiondescription {1}" #~ msgid "" #~ "IP \"{ip[\"value\"]}\" ({ip[\"name\"]}) with this netmask is in fact a " diff --git a/locale/tiramisu.pot b/locale/tiramisu.pot index 193f8f8..1322953 100644 --- a/locale/tiramisu.pot +++ b/locale/tiramisu.pot @@ -5,7 +5,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2025-03-19 09:54+0100\n" +"POT-Creation-Date: 2025-04-09 08:16+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -79,7 +79,7 @@ msgstr "" msgid "cannot find \"{0}\" in option \"{1}\" at index \"{2}\"" msgstr "" -#: tiramisu/api.py:679 +#: tiramisu/api.py:679 tiramisu/option/optiondescription.py:283 msgid "cannot find \"{0}\"" msgstr "" @@ -532,7 +532,7 @@ msgstr "" msgid "some characters are uppercase" msgstr "" -#: tiramisu/option/dynoptiondescription.py:131 +#: tiramisu/option/dynoptiondescription.py:130 msgid "DynOptionDescription identifiers for option {0}, is not a list ({1})" msgstr "" @@ -700,35 +700,31 @@ msgstr "" msgid "duplicate option: {0}" msgstr "" -#: tiramisu/option/optiondescription.py:244 -msgid "unknown option \"{0}\" in root optiondescription (it's a dynamic option)" +#: tiramisu/option/optiondescription.py:249 +msgid "cannot access to \"{0}\" it's a dynamic option" msgstr "" -#: tiramisu/option/optiondescription.py:279 -msgid "unknown option \"{0}\" in root optiondescription" +#: tiramisu/option/optiondescription.py:286 +msgid "cannot find \"{0}\" in \"{1}\"" msgstr "" -#: tiramisu/option/optiondescription.py:282 -msgid "unknown option \"{0}\" in optiondescription {1}" -msgstr "" - -#: tiramisu/option/optiondescription.py:338 +#: tiramisu/option/optiondescription.py:342 msgid "children in optiondescription \"{}\" must be a list" msgstr "" -#: tiramisu/option/optiondescription.py:366 +#: tiramisu/option/optiondescription.py:370 msgid "duplicate option name: \"{0}\"" msgstr "" -#: tiramisu/option/optiondescription.py:372 +#: tiramisu/option/optiondescription.py:376 msgid "the option's name \"{0}\" start as the dynoptiondescription's name \"{1}\"" msgstr "" -#: tiramisu/option/optiondescription.py:415 +#: tiramisu/option/optiondescription.py:419 msgid "cannot change group_type if already set (old {0}, new {1})" msgstr "" -#: tiramisu/option/optiondescription.py:420 +#: tiramisu/option/optiondescription.py:424 msgid "group_type: {0} not allowed" msgstr "" diff --git a/tests/test_config.py b/tests/test_config.py index 7efb323..56f1ee5 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -380,12 +380,12 @@ def test_prefix_error(): try: cfg.option('test1').value.set('yes') except Exception as err: - assert str(err) == _('"{0}" is an invalid {1} for "{2}"').format('yes', _('integer'), 'test1') + assert str(err) == _('"{0}" is an invalid {1} for "{2}", which is not an integer').format('yes', _('integer'), 'test1') try: cfg.option('test1').value.set('yes') except Exception as err: err.prefix = '' - assert str(err) == _('invalid value') + assert str(err) == _('which is not an integer') # assert not list_sessions() diff --git a/tiramisu/locale/fr/LC_MESSAGES/tiramisu.mo b/tiramisu/locale/fr/LC_MESSAGES/tiramisu.mo index a1b4837ec355f508aff2a1356fbad9dca5d2002a..9c16744b0f98aeef12d7290196148e8b6df883e6 100644 GIT binary patch delta 3682 zcmZA3c~Dhl9LDjNMGVOW+*m{|mk?Y~+>lU$1b0nLb0IfCR4Nfd2~xaZxo_E3TeQX0 z(n?dWyX9JHCAj78*f`@qBF)kBIM;B_31279SaSf*74NS#oKCR>9P#0K_g}4P%FtVBTxsmu7<5d`r z`%x3VfHC+0{V=*Y=W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&tkv#Q!)8Sn5TzYmr-+7f~H;Uv0N*7?Wvl!;ZKYwF^#SUp$KiT3z0` zc2$qZuKZ&Y>coTCA5Wo%II+h57G$H=!g$QayHOq8jJo~=>H$BZR(bv{c0?zmrsxsW z@z>GI^UYaR@F&c{)S%t(12I6m0`;wKKo4#vDo4nJL=RQD%wj&qy{>+nvzb3qIZar< zv6qV!Q@N9TM%EGyQD^f!4Bh95Rm2u?nq>i*9Di4v@$VqYqDJN5jO2}dk<11vYYp=mx zu6_)YTs`sx6}~yYD9_UR)E$}PT;AdgZATTYe(jXMsX5k)=>Dikgw%G zeZi2gE*xIy4pvpySJnk%7yqB9`*MQ|yVv{X_^K9%=F|o&-3{~XZKD1G``bk`MwG@y z?<(o&FaMt|RE9&LMb*BlIiY&ryzcg&ExO`U?|=1@rf_Lm)^DBRjq~L;ohwfF diff --git a/tiramisu/option/dynoptiondescription.py b/tiramisu/option/dynoptiondescription.py index 47f8dba..d840db9 100644 --- a/tiramisu/option/dynoptiondescription.py +++ b/tiramisu/option/dynoptiondescription.py @@ -124,7 +124,6 @@ class DynOptionDescription(OptionDescription): )[0] if values is None: values = [] - values_ = [] if __debug__: if not isinstance(values, list): raise ValueError( @@ -134,6 +133,7 @@ class DynOptionDescription(OptionDescription): self.impl_get_display_name(subconfig, with_quote=True), values ) ) + values_ = [] for val in values: cval = self.convert_identifier_to_path(val) if not isinstance(cval, str) or re.match(NAME_REGEXP, cval) is None: diff --git a/tiramisu/option/optiondescription.py b/tiramisu/option/optiondescription.py index b1ba72e..c086050 100644 --- a/tiramisu/option/optiondescription.py +++ b/tiramisu/option/optiondescription.py @@ -232,18 +232,21 @@ class OptionDescriptionWalk(CacheOptionDescription): def get_child_not_dynamic( self, - name, - allow_dynoption, + name: str, + allow_dynoption: bool, + parent: "SubConfig", ): if name in self._children[0]: # pylint: disable=no-member option = self._children[1][ self._children[0].index(name) ] # pylint: disable=no-member if option.impl_is_dynoptiondescription() and not allow_dynoption: + if parent.path: + path = parent.path + '.' + name + else: + path = name raise AttributeError( - _( - 'unknown option "{0}" in root optiondescription (it\'s a dynamic option)' - ).format(name) + _('cannot access to "{0}" it\'s a dynamic option').format(path) ) return option @@ -261,6 +264,7 @@ class OptionDescriptionWalk(CacheOptionDescription): option = self.get_child_not_dynamic( name, allow_dynoption, + parent, ) if option: return option @@ -274,13 +278,13 @@ class OptionDescriptionWalk(CacheOptionDescription): if not with_identifier: return child return identifier, child - if self.impl_get_group_type() == groups.root: # pylint: disable=no-member + if parent.path is None: raise AttributeError( - _('unknown option "{0}" in root optiondescription').format(name) + _('cannot find "{0}"').format(name) ) raise AttributeError( - _('unknown option "{0}" in optiondescription {1}').format( - name, self.impl_get_display_name(parent, with_quote=True) + _('cannot find "{0}" in "{1}"').format( + name, parent.path ) )