diff --git a/src/rougail/user_datas.py b/src/rougail/user_datas.py index 7bfa04cf8..8d040ab78 100644 --- a/src/rougail/user_datas.py +++ b/src/rougail/user_datas.py @@ -49,16 +49,22 @@ class UserDatas: self, user_datas: List[dict], *, - user_datas_type: str = "user_datas", + invalid_user_datas_error: bool = False, + unknown_user_datas_error: bool = False, ): self.values = {} self.errors = [] self.warnings = [] - self.show_secrets = False - if user_datas_type == "user_datas": - self._populate_values(user_datas) + if invalid_user_datas_error: + self.invalids = self.errors else: - self.values = user_datas + self.invalids = self.warnings + if unknown_user_datas_error: + self.unknowns = self.errors + else: + self.unknowns = self.warnings + self.show_secrets = False + self._populate_values(user_datas) self._auto_configure_dynamics() self._populate_config() self.properties_to_string = get_properties_to_string() @@ -126,7 +132,7 @@ class UserDatas: lists = config.list(uncalculated=True) except PropertiesOptionError: lists = [] - for tconfig in []: + for tconfig in lists: if not tconfig.isdynamic(only_self=True): # it's not a dynamic variable continue @@ -139,7 +145,7 @@ class UserDatas: msg = _( 'cannot load variable path "{0}", the identifier "{1}" is not valid in {2}' ).format(path, identifier, data["source"]) - self.warnings.append(msg) + self.invalids.append(msg) continue if identifier is None: # it's a dynamic variable but doesn't match the current name @@ -298,7 +304,7 @@ class UserDatas: try: if option.isoptiondescription(): if value: - self.warnings.append( + self.invalids.append( _( 'cannot set the value "{0}" to the family {1}, it will be ignored when loading from {2}' ).format( @@ -308,21 +314,25 @@ class UserDatas: ) ) continue + except PropertiesOptionError as err: + self.unknowns.append( + _("{0} loaded from {1}").format(err, options["source"]) + ) except AttributeOptionError as err: if err.code == "option-not-found": - self.warnings.append( + self.unknowns.append( _( 'variable or family "{0}" does not exist, it will be ignored when loading from {1}' ).format(err.path, options["source"]) ) elif err.code == "option-dynamic": - self.warnings.append( + self.invalids.append( _( '"{0}" is the name of a dynamic family, it will be ignored when loading from {1}' ).format(option.description(with_quote=True), options["source"]) ) else: - self.warnings.append( + self.invalids.append( _("{0} loaded from {1}").format(err, options["source"]) ) continue @@ -350,7 +360,7 @@ class UserDatas: display_name = option.description(with_quote=True) if index is not None: if path == err_path: - self.warnings.append( + self.unknowns.append( _( 'variable {0} at index "{1}" is {2}, it will be ignored when loading from {3}' ).format( @@ -361,7 +371,7 @@ class UserDatas: ) ) else: - self.warnings.append( + self.unknowns.append( _( 'family {0} is {1}, {2} at index "{3}" will be ignored when loading from {4}' ).format( @@ -374,7 +384,7 @@ class UserDatas: ) else: if path == err_path: - self.warnings.append( + self.unknowns.append( _( "variable {0} is {1}, it will be ignored when loading from {2}" ).format( @@ -382,7 +392,7 @@ class UserDatas: ) ) else: - self.warnings.append( + self.unknowns.append( _( "family {0} is {1}, {2} will be ignored when loading from {3}" ).format( @@ -393,16 +403,16 @@ class UserDatas: ) ) else: - self.warnings.append( + self.unknowns.append( _("{0} in {1}").format(err, options["source"]) ) except LeadershipError as err: - self.warnings.append(_("{0} in {1}").format(err, options["source"])) + self.unknowns.append(_("{0} in {1}").format(err, options["source"])) except ValueError as err: err.prefix = "" if index is not None: type_ = option.type(translation=True) - self.warnings.append( + self.invalids.append( _( 'the value "{0}" is an invalid {1} for {2} at index "{3}", {4}, it will be ignored when loading from {5}' ).format( @@ -416,7 +426,7 @@ class UserDatas: ) else: type_ = option.type(translation=True) - self.warnings.append( + self.invalids.append( _( 'the value "{0}" is an invalid {1} for {2}, {3}, it will be ignored when loading from {4}' ).format(