diff --git a/python/podio/podio_config_reader.py b/python/podio/podio_config_reader.py index b6836f0d3..c3d9b4106 100644 --- a/python/podio/podio_config_reader.py +++ b/python/podio/podio_config_reader.py @@ -57,7 +57,7 @@ def _parse_with_regexps(string, regexps_callbacks): if result: return callback(result) - raise DefinitionError(f"'{string}' is not a valid member definition") + raise DefinitionError(f"'{string}' is not a valid member definition. Check syntax of the member definition.") @staticmethod def _full_array_conv(result): @@ -85,18 +85,26 @@ def _bare_member_conv(result): def parse(self, string, require_description=True): """Parse the passed string""" - matchers_cbs = [ + default_matchers_cbs = [ (self.full_array_re, self._full_array_conv), - (self.member_re, self._full_member_conv) - ] - - if not require_description: - matchers_cbs.extend(( - (self.bare_array_re, self._bare_array_conv), - (self.bare_member_re, self._bare_member_conv) - )) - - return self._parse_with_regexps(string, matchers_cbs) + (self.member_re, self._full_member_conv)] + + no_desc_matchers_cbs = [ + (self.bare_array_re, self._bare_array_conv), + (self.bare_member_re, self._bare_member_conv)] + + if require_description: + try: + return self._parse_with_regexps(string, default_matchers_cbs) + except DefinitionError: + # check whether we could parse this if we don't require a description and + # provide more details in the error if we can + self._parse_with_regexps(string, no_desc_matchers_cbs) + # pylint: disable-next=raise-missing-from + raise DefinitionError(f"'{string}' is not a valid member definition. Description comment is missing.\n" + "Correct Syntax: // ") + + return self._parse_with_regexps(string, default_matchers_cbs + no_desc_matchers_cbs) class ClassDefinitionValidator: