better error msg

This commit is contained in:
Emmanuel Garette 2016-10-23 23:18:06 +02:00
parent 9a912376b9
commit 44dfd21ff6
3 changed files with 11 additions and 12 deletions

View File

@ -50,7 +50,7 @@ class PropertiesOptionError(AttributeError):
else: else:
prop_msg = _('properties') prop_msg = _('properties')
msg = display_list(msg) msg = display_list(msg)
return _('cannot access to {0} {1} because has {2} {3}').format(self._type, self._datas['path'], prop_msg, msg) return _('cannot access to {0} "{1}" because has {2} {3}').format(self._type, self._datas['opt'].impl_get_display_name(), prop_msg, msg)
else: else:
return super(PropertiesOptionError, self).__str__() return super(PropertiesOptionError, self).__str__()

View File

@ -362,6 +362,12 @@ class BaseOption(Base):
if not isinstance(value, unicode) and not isinstance(value, str): if not isinstance(value, unicode) and not isinstance(value, str):
return ValueError(_('invalid unicode or string')) return ValueError(_('invalid unicode or string'))
def impl_get_display_name(self):
name = self.impl_getdoc()
if name is None or name == '':
name = self.impl_getname()
return name
class OnlyOption(BaseOption): class OnlyOption(BaseOption):
__slots__ = tuple() __slots__ = tuple()
@ -633,12 +639,6 @@ class Option(OnlyOption):
"accesses the Option's doc" "accesses the Option's doc"
return self.impl_get_information('doc') return self.impl_get_information('doc')
def impl_get_display_name(self):
name = self.impl_getdoc()
if name is None or name == '':
name = self.impl_getname()
return name
def _valid_consistencies(self, other_opts, init=True): def _valid_consistencies(self, other_opts, init=True):
if self._is_subdyn(): if self._is_subdyn():
dynod = self._impl_getsubdyn() dynod = self._impl_getsubdyn()
@ -906,7 +906,6 @@ def validate_requires_arg(multi, requires, name):
inverse, transitive, same_action) inverse, transitive, same_action)
else: else:
ret_requires[action][option][1].append(expected) ret_requires[action][option][1].append(expected)
option._set_has_dependency()
# transform dict to tuple # transform dict to tuple
ret = [] ret = []
for opt_requires in ret_requires.values(): for opt_requires in ret_requires.values():

View File

@ -517,7 +517,7 @@ class Settings(object):
return PropertiesOptionError(_("cannot access to {0} {1} " return PropertiesOptionError(_("cannot access to {0} {1} "
"because has {2} {3}" "because has {2} {3}"
"").format(opt_type, "").format(opt_type,
opt_or_descr._name, opt_or_descr.impl_get_display_name(),
prop_msg, prop_msg,
display_list(props)), props, display_list(props)), props,
self, datas, opt_type) self, datas, opt_type)
@ -689,10 +689,10 @@ class Settings(object):
calc_properties.setdefault(action, []).extend(msg) calc_properties.setdefault(action, []).extend(msg)
else: else:
if not inverse: if not inverse:
msg = _("the value of {0} is {1}") msg = _('the value of "{0}" is {1}')
else: else:
msg = _("the value of {0} is not {1}") msg = _('the value of "{0}" is not {1}')
calc_properties.setdefault(action, []).append(msg.format(reqpath, display_list(expected, 'or'))) calc_properties.setdefault(action, []).append(msg.format(option.impl_get_display_name(), display_list(expected, 'or')))
else: else:
calc_properties.add(action) calc_properties.add(action)
break break