From 49b91460654718c9637fdf6091220b433c46bbaf Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Fri, 3 Jul 2020 00:33:44 +0200 Subject: [PATCH] [fix] reintroduce custom exceptions for input fields type --- src/yunohost/app.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/yunohost/app.py b/src/yunohost/app.py index 4abaaecca..9c76e73eb 100644 --- a/src/yunohost/app.py +++ b/src/yunohost/app.py @@ -2434,8 +2434,7 @@ class YunoHostArgumentFormatParser(object): # we have an answer, do some post checks if question.value is not None: if question.choices and question.value not in question.choices: - raise YunohostError('app_argument_choice_invalid', name=question.name, - choices=', '.join(question.choices)) + self._raise_invalide_answer(question) # this is done to enforce a certain formating like for boolean # by default it doesn't do anything @@ -2443,6 +2442,10 @@ class YunoHostArgumentFormatParser(object): return (question.value, self.argument_type) + def _raise_invalide_answer(self, question): + raise YunohostError('app_argument_choice_invalid', name=question.name, + choices=', '.join(question.choices)) + def _format_text_for_user_input_in_cli(self, question): text_for_user_input_in_cli = _value_for_locale(question.ask) @@ -2534,6 +2537,10 @@ class DomainArgumentParser(YunoHostArgumentFormatParser): return question + def _raise_invalide_answer(self, question): + raise YunohostError('app_argument_invalid', name=question.name, + error=m18n.n('domain_unknown')) + class UserArgumentParser(YunoHostArgumentFormatParser): argument_type = "user" @@ -2546,6 +2553,10 @@ class UserArgumentParser(YunoHostArgumentFormatParser): return question + def _raise_invalide_answer(self, question): + raise YunohostError('app_argument_invalid', name=question.name, + error=m18n.n('user_unknown', user=question.value)) + class AppArgumentParser(YunoHostArgumentFormatParser): argument_type = "app" @@ -2558,6 +2569,10 @@ class AppArgumentParser(YunoHostArgumentFormatParser): return question + def _raise_invalide_answer(self, question): + raise YunohostError('app_argument_invalid', name=question.name, + error=m18n.n('app_unknown')) + class DisplayTextArgumentParser(YunoHostArgumentFormatParser):