From 5bf75b38241e01754d876ac662631ed6958732a4 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Sun, 12 Feb 2017 10:38:57 +0100 Subject: [PATCH] error in external function should returns only ConfigError --- ChangeLog | 4 ++++ test/test_option_calculation.py | 4 ++-- test/test_option_validator.py | 6 +++--- tiramisu/autolib.py | 16 +++++++++++++--- translations/fr/tiramisu.po | 20 ++++++++++++++++---- translations/tiramisu.pot | 10 +++++++--- 6 files changed, 45 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index f4862b1..882742f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Sun Feb 12 10:30:13 2017 +0200 Emmanuel Garette + * error in external function should returns explicit error message + all errors will be ConfigError + Thu Jan 12 19:49:41 2017 +0200 Emmanuel Garette * can mix inversed and non inversed requires * validator's function can have 1 arg, 2 args or 3 args without diff --git a/test/test_option_calculation.py b/test/test_option_calculation.py index c53a203..e2e6b01 100644 --- a/test/test_option_calculation.py +++ b/test/test_option_calculation.py @@ -993,9 +993,9 @@ def test_callback_raise(): cfg.read_write() try: cfg.od1.opt1 - except Exception, err: + except ConfigError, err: assert '"Option 1"' in str(err) try: cfg.od2.opt2 - except ValueError, err: + except ConfigError, err: assert '"Option 2"' in str(err) diff --git a/test/test_option_validator.py b/test/test_option_validator.py index da59d2a..da28f25 100644 --- a/test/test_option_validator.py +++ b/test/test_option_validator.py @@ -7,7 +7,7 @@ from py.test import raises from tiramisu.config import Config from tiramisu.option import BoolOption, StrOption, OptionDescription from tiramisu.setting import groups -from tiramisu.error import ValueWarning +from tiramisu.error import ValueWarning, ConfigError from tiramisu.i18n import _ @@ -183,7 +183,7 @@ def test_validator_params_value_values_index_slave(): def test_validator_params_value_values_notmulti(): - raises(TypeError, "opt1 = StrOption('opt1', '', validator=value_values, default='val')") + raises(ConfigError, "opt1 = StrOption('opt1', '', validator=value_values, default='val')") def test_validator_params_value_values_kwargs_empty(): @@ -286,7 +286,7 @@ def test_validator_params_context(): def test_validator_params_key(): opt1 = StrOption('opt1', '', validator=return_true, validator_params={'param': ('yes',)}, default='val') - raises(TypeError, "StrOption('opt2', '', validator=return_true, validator_params={'param_unknown': ('yes',)}, default='val')") + raises(ConfigError, "StrOption('opt2', '', validator=return_true, validator_params={'param_unknown': ('yes',)}, default='val')") root = OptionDescription('root', '', [opt1]) cfg = Config(root) assert cfg.opt1 == 'val' diff --git a/tiramisu/autolib.py b/tiramisu/autolib.py index 9d54138..1ceb0a7 100644 --- a/tiramisu/autolib.py +++ b/tiramisu/autolib.py @@ -260,6 +260,16 @@ def calculate(option, callback, is_validator, args, kwargs): error = err except Exception as err: error = err - raise error.__class__(_('function "{0}" returns "{1}" for option "{2}"').format(callback.func_name, - option.impl_get_display_name(), - str(err))) + if len(args) != 0 or len(kwargs) != 0: + msg = _('unexpected error "{0}" in function "{1}" with arguments "{3}" and "{4}" ' + 'for option "{2}"').format(str(error), + callback.func_name, + option.impl_get_display_name(), + args, + kwargs) + else: + msg = _('unexpected error "{0}" in function "{1}" for option "{2}"' + '').format(str(error), + callback.func_name, + option.impl_get_display_name()) + raise ConfigError(msg) diff --git a/translations/fr/tiramisu.po b/translations/fr/tiramisu.po index 5406765..7bd4207 100644 --- a/translations/fr/tiramisu.po +++ b/translations/fr/tiramisu.po @@ -2,7 +2,7 @@ msgid "" msgstr "" "Project-Id-Version: Tiramisu\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2017-02-11 18:05+0100\n" +"POT-Creation-Date: 2017-02-12 10:35+0100\n" "PO-Revision-Date: \n" "Last-Translator: Emmanuel Garette \n" "Language-Team: Tiramisu's team \n" @@ -26,9 +26,18 @@ msgid "callback cannot return a list for a slave option ({0})" msgstr "" "un calcul ne peut pas retourner une liste pour une option esclave ({0})" -#: tiramisu/autolib.py:263 -msgid "function \"{0}\" returns \"{1}\" for option \"{2}\"" -msgstr "la fonction \"{0}\" retourne \"{1}\" pour l'option \"{2}\"" +#: tiramisu/autolib.py:264 +msgid "" +"unexpected error \"{0}\" in function \"{1}\" with arguments \"{3}\" and " +"\"{4}\" for option \"{2}\"" +msgstr "" +"erreur inattendue \"{0}\" dans la fonction \"{1}\" avec les arguments " +"\"{3}\" et \"{4}\" pour l'option \"{2}\"" + +#: tiramisu/autolib.py:271 +msgid "unexpected error \"{0}\" in function \"{1}\" for option \"{2}\"" +msgstr "" +"erreur inattendue \"{0}\" dans la fonction \"{1}\" pour l'option \"{2}\"" #: tiramisu/config.py:64 msgid "descr must be an optiondescription, not {0}" @@ -931,6 +940,9 @@ msgstr "ne peut étendre une option multi {0} pour une maître ou une esclave" msgid "cannot pop a value on a multi option {0} which is a slave" msgstr "ne peut supprimer une valeur dans l'option multi {0} qui est esclave" +#~ msgid "function \"{0}\" returns \"{1}\" for option \"{2}\"" +#~ msgstr "la fonction \"{0}\" retourne \"{1}\" pour l'option \"{2}\"" + #~ msgid "not allowed default value for option {0} in group {1}" #~ msgstr "valeur de défaut non autorisée pour l'option {0} du groupe {1}" diff --git a/translations/tiramisu.pot b/translations/tiramisu.pot index 6dba0b8..b8c01a3 100644 --- a/translations/tiramisu.pot +++ b/translations/tiramisu.pot @@ -5,7 +5,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2017-02-11 18:04+CET\n" +"POT-Creation-Date: 2017-02-12 10:34+CET\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -23,8 +23,12 @@ msgstr "" msgid "callback cannot return a list for a slave option ({0})" msgstr "" -#: tiramisu/autolib.py:263 -msgid "function \"{0}\" returns \"{1}\" for option \"{2}\"" +#: tiramisu/autolib.py:264 +msgid "unexpected error \"{0}\" in function \"{1}\" with arguments \"{3}\" and \"{4}\" for option \"{2}\"" +msgstr "" + +#: tiramisu/autolib.py:271 +msgid "unexpected error \"{0}\" in function \"{1}\" for option \"{2}\"" msgstr "" #: tiramisu/config.py:64