mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Simplify error management
This commit is contained in:
parent
6b8cb0c005
commit
74102b607d
2 changed files with 7 additions and 24 deletions
|
@ -13,7 +13,7 @@
|
||||||
"app_already_installed": "{app} is already installed",
|
"app_already_installed": "{app} is already installed",
|
||||||
"app_already_installed_cant_change_url": "This app is already installed. The URL cannot be changed just by this function. Check in `app changeurl` if it's available.",
|
"app_already_installed_cant_change_url": "This app is already installed. The URL cannot be changed just by this function. Check in `app changeurl` if it's available.",
|
||||||
"app_already_up_to_date": "{app} is already up-to-date",
|
"app_already_up_to_date": "{app} is already up-to-date",
|
||||||
"app_argument_choice_invalid": "Use one of these choices '{choices}' for the argument '{name}' instead of '{value}'",
|
"app_argument_choice_invalid": "Pick a valid value for argument '{name}': '{value}' is not among the available choices ({choices})",
|
||||||
"app_argument_invalid": "Pick a valid value for the argument '{name}': {error}",
|
"app_argument_invalid": "Pick a valid value for the argument '{name}': {error}",
|
||||||
"app_argument_password_no_default": "Error while parsing password argument '{name}': password argument can't have a default value for security reason",
|
"app_argument_password_no_default": "Error while parsing password argument '{name}': password argument can't have a default value for security reason",
|
||||||
"app_argument_required": "Argument '{name}' is required",
|
"app_argument_required": "Argument '{name}' is required",
|
||||||
|
|
|
@ -549,7 +549,12 @@ class Question(object):
|
||||||
# we have an answer, do some post checks
|
# we have an answer, do some post checks
|
||||||
if self.value not in [None, ""]:
|
if self.value not in [None, ""]:
|
||||||
if self.choices and self.value not in self.choices:
|
if self.choices and self.value not in self.choices:
|
||||||
self._raise_invalid_answer()
|
raise YunohostValidationError(
|
||||||
|
"app_argument_choice_invalid",
|
||||||
|
name=self.name,
|
||||||
|
value=self.value,
|
||||||
|
choices=", ".join(self.choices),
|
||||||
|
)
|
||||||
if self.pattern and not re.match(self.pattern["regexp"], str(self.value)):
|
if self.pattern and not re.match(self.pattern["regexp"], str(self.value)):
|
||||||
raise YunohostValidationError(
|
raise YunohostValidationError(
|
||||||
self.pattern["error"],
|
self.pattern["error"],
|
||||||
|
@ -557,14 +562,6 @@ class Question(object):
|
||||||
value=self.value,
|
value=self.value,
|
||||||
)
|
)
|
||||||
|
|
||||||
def _raise_invalid_answer(self):
|
|
||||||
raise YunohostValidationError(
|
|
||||||
"app_argument_choice_invalid",
|
|
||||||
name=self.name,
|
|
||||||
value=self.value,
|
|
||||||
choices=", ".join(self.choices),
|
|
||||||
)
|
|
||||||
|
|
||||||
def _format_text_for_user_input_in_cli(self):
|
def _format_text_for_user_input_in_cli(self):
|
||||||
|
|
||||||
text_for_user_input_in_cli = _value_for_locale(self.ask)
|
text_for_user_input_in_cli = _value_for_locale(self.ask)
|
||||||
|
@ -847,13 +844,6 @@ class DomainQuestion(Question):
|
||||||
|
|
||||||
self.choices = domain_list()["domains"]
|
self.choices = domain_list()["domains"]
|
||||||
|
|
||||||
def _raise_invalid_answer(self):
|
|
||||||
raise YunohostValidationError(
|
|
||||||
"app_argument_invalid",
|
|
||||||
name=self.name,
|
|
||||||
error=m18n.n("domain_name_unknown", domain=self.value),
|
|
||||||
)
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def normalize(value, option={}):
|
def normalize(value, option={}):
|
||||||
if value.startswith("https://"):
|
if value.startswith("https://"):
|
||||||
|
@ -891,13 +881,6 @@ class UserQuestion(Question):
|
||||||
self.default = user
|
self.default = user
|
||||||
break
|
break
|
||||||
|
|
||||||
def _raise_invalid_answer(self):
|
|
||||||
raise YunohostValidationError(
|
|
||||||
"app_argument_invalid",
|
|
||||||
name=self.name,
|
|
||||||
error=m18n.n("user_unknown", user=self.value),
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class NumberQuestion(Question):
|
class NumberQuestion(Question):
|
||||||
argument_type = "number"
|
argument_type = "number"
|
||||||
|
|
Loading…
Add table
Reference in a new issue