From 6181b728ad2e4064c646dcf934bdcd40f1a14730 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Sat, 4 Jan 2025 17:39:25 +0100 Subject: [PATCH] fix: message error improvment --- tiramisu/option/domainnameoption.py | 18 ++++++++++++------ tiramisu/option/filenameoption.py | 5 +++-- tiramisu/option/stroption.py | 2 +- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/tiramisu/option/domainnameoption.py b/tiramisu/option/domainnameoption.py index 756c515..331524d 100644 --- a/tiramisu/option/domainnameoption.py +++ b/tiramisu/option/domainnameoption.py @@ -76,14 +76,20 @@ class DomainnameOption(StrOption): regexp = r"((?!-)[a-z0-9-]{{{1},{0}}}\.){{{1},}}[a-z0-9-]{{1,{0}}}".format( self._get_len(type), min_time ) + msg = _( + 'must start with lowercase characters followed by lowercase characters, number, "-" and "." characters are allowed' + ) + msg_warning = _( + 'must start with lowercase characters followed by lowercase characters, number, "-" and "." characters are recommanded' + ) else: regexp = r"((?!-)[a-z0-9-]{{1,{0}}})".format(self._get_len(type)) - msg = _( - 'must start with lowercase characters followed by lowercase characters, number, "-" and "." characters are allowed' - ) - msg_warning = _( - 'must start with lowercase characters followed by lowercase characters, number, "-" and "." characters are recommanded' - ) + msg = _( + 'must start with lowercase characters followed by lowercase characters, number and "-" characters are allowed' + ) + msg_warning = _( + 'must start with lowercase characters followed by lowercase characters, number and "-" characters are recommanded' + ) if allow_ip: msg = _("could be a IP, otherwise {}").format(msg) msg_warning = _("could be a IP, otherwise {}").format(msg_warning) diff --git a/tiramisu/option/filenameoption.py b/tiramisu/option/filenameoption.py index bfcf0e8..e9dbf5f 100644 --- a/tiramisu/option/filenameoption.py +++ b/tiramisu/option/filenameoption.py @@ -74,8 +74,9 @@ class FilenameOption(StrOption): if not found and "directory" in types and file.is_dir(): found = True if not found: + translated_types = [{"file": _("file"), "directory": _("directory")}.get(typ) for typ in types] raise ValueError( - _('cannot find {0} "{1}"').format( - display_list(types, separator="or"), value + _('cannot find this {0}').format( + display_list(translated_types, separator="or"), value ) ) diff --git a/tiramisu/option/stroption.py b/tiramisu/option/stroption.py index a4b7faa..b8a9a22 100644 --- a/tiramisu/option/stroption.py +++ b/tiramisu/option/stroption.py @@ -38,7 +38,7 @@ class StrOption(Option): ) -> None: """validation""" if not isinstance(value, str): - raise ValueError() + raise ValueError(_('which is not a string')) class RegexpOption(StrOption):