feat: better error messages
This commit is contained in:
parent
b443771c30
commit
f33713231e
3 changed files with 25 additions and 6 deletions
|
@ -22,7 +22,7 @@ from typing import Any, Optional, Union, Callable, Dict, List
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
import weakref
|
import weakref
|
||||||
|
|
||||||
from .error import PropertiesOptionError, ConfigError, LeadershipError, ValueWarning, CancelParam
|
from .error import PropertiesOptionError, ConfigError, LeadershipError, ValueWarning, CancelParam, display_list
|
||||||
from .i18n import _
|
from .i18n import _
|
||||||
from .setting import undefined, ConfigBag
|
from .setting import undefined, ConfigBag
|
||||||
from .function import FUNCTION_WAITING_FOR_DICT, FUNCTION_WAITING_FOR_ERROR
|
from .function import FUNCTION_WAITING_FOR_DICT, FUNCTION_WAITING_FOR_ERROR
|
||||||
|
@ -682,7 +682,9 @@ def manager_callback(
|
||||||
child_path = name
|
child_path = name
|
||||||
if param.optional:
|
if param.optional:
|
||||||
raise CancelParam(callbk_option.impl_getpath(), child_path)
|
raise CancelParam(callbk_option.impl_getpath(), child_path)
|
||||||
msg = _('cannot calculate arguments for "{0}", cannot find dynamic variable "{1}"').format(subconfig.path, child_path)
|
|
||||||
|
identifiers = display_list(doption.get_identifiers(parent), add_quote=True)
|
||||||
|
msg = _('cannot calculate arguments for "{0}", cannot find dynamic variable "{1}" with identifier "{2}", list of valid identifiers: {3}').format(subconfig.path, doption.impl_getpath(), identifier, identifiers)
|
||||||
raise ConfigError(msg) from err
|
raise ConfigError(msg) from err
|
||||||
new_parents.append(
|
new_parents.append(
|
||||||
parent.get_child(
|
parent.get_child(
|
||||||
|
|
|
@ -220,9 +220,9 @@ class ValueOptionError(_CommonError, ValueError):
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
if ValueOptionError.tmpl is None:
|
if ValueOptionError.tmpl is None:
|
||||||
if kwargs.get('index') is None:
|
if kwargs.get('index') is None:
|
||||||
ValueOptionError.tmpl = _('"{0}" is an invalid {1} for "{2}"')
|
self.tmpl = _('"{0}" is an invalid {1} for "{2}"')
|
||||||
else:
|
else:
|
||||||
ValueOptionError.tmpl = _('"{0}" is an invalid {1} for "{2}" at index "{3}"')
|
self.tmpl = _('"{0}" is an invalid {1} for "{2}" at index "{3}"')
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
@ -240,3 +240,12 @@ class CancelParam(Exception):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.origin_path = origin_path
|
self.origin_path = origin_path
|
||||||
self.current_path = current_path
|
self.current_path = current_path
|
||||||
|
|
||||||
|
def __ne__(self, value):
|
||||||
|
return value is None or value == ""
|
||||||
|
|
||||||
|
def __eq__(self, value):
|
||||||
|
return value is None or value == ""
|
||||||
|
|
||||||
|
def __bool__(self):
|
||||||
|
return False
|
||||||
|
|
|
@ -110,10 +110,18 @@ class URLOption(StrOption):
|
||||||
domain, port, files = self._get_domain_port_files(value)
|
domain, port, files = self._get_domain_port_files(value)
|
||||||
# validate port
|
# validate port
|
||||||
portoption = self.impl_get_extra("_port")
|
portoption = self.impl_get_extra("_port")
|
||||||
portoption.validate(port)
|
try:
|
||||||
|
portoption.validate(port)
|
||||||
|
except ValueError as err:
|
||||||
|
msg = _('the port "{0}" is invalid: {1}').format(domain, err)
|
||||||
|
raise ValueError(msg) from err
|
||||||
# validate domainname
|
# validate domainname
|
||||||
domainnameoption = self.impl_get_extra("_domainname")
|
domainnameoption = self.impl_get_extra("_domainname")
|
||||||
domainnameoption.validate(domain)
|
try:
|
||||||
|
domainnameoption.validate(domain)
|
||||||
|
except ValueError as err:
|
||||||
|
msg = _('the domain "{0}" is invalid: {1}').format(domain, err)
|
||||||
|
raise ValueError(msg) from err
|
||||||
# validate files
|
# validate files
|
||||||
if files is not None and files != "" and not self.path_re.search(files):
|
if files is not None and files != "" and not self.path_re.search(files):
|
||||||
raise ValueError(_("must ends with a valid resource name"))
|
raise ValueError(_("must ends with a valid resource name"))
|
||||||
|
|
Loading…
Reference in a new issue