better error message if option that does not exists is in root optiondescription

This commit is contained in:
2019-10-16 07:31:52 +02:00
parent 42291aec51
commit 280d2ebd0a
7 changed files with 43 additions and 27 deletions

View File

@ -222,9 +222,14 @@ class OptionDescriptionWalk(CacheOptionDescription):
if name == cname + suffix:
return child.to_dynoption(subpath,
suffix)
raise AttributeError(_('unknown option "{0}" '
'in optiondescription "{1}"'
'').format(name, self.impl_getname()))
if self.impl_get_group_type() == groups.root:
raise AttributeError(_('unknown option "{0}" '
'in root optiondescription'
'').format(name))
else:
raise AttributeError(_('unknown option "{0}" '
'in optiondescription "{1}"'
'').format(name, self.impl_get_display_name()))
def get_children(self,
config_bag: Union[ConfigBag, Undefined],
@ -329,15 +334,16 @@ class OptionDescription(OptionDescriptionWalk):
:param group_type: an instance of `GroupType` or `LeadershipGroupType`
that lives in `setting.groups`
"""
if self._group_type != groups.default:
raise ValueError(_('cannot change group_type if already set '
'(old {0}, new {1})').format(self._group_type,
group_type))
if not isinstance(group_type, groups.GroupType):
raise ValueError(_('group_type: {0}'
' not allowed').format(group_type))
if isinstance(group_type, groups.LeadershipGroupType):
raise ConfigError('please use Leadership object instead of OptionDescription')
if __debug__:
if self._group_type != groups.default:
raise ValueError(_('cannot change group_type if already set '
'(old {0}, new {1})').format(self._group_type,
group_type))
if not isinstance(group_type, groups.GroupType):
raise ValueError(_('group_type: {0}'
' not allowed').format(group_type))
if isinstance(group_type, groups.LeadershipGroupType):
raise ConfigError('please use Leadership object instead of OptionDescription')
self._group_type = group_type
def impl_get_group_type(self) -> groups.GroupType: