Skip to content

Commit

Permalink
Make error message from parsing more explicit (#437)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ananya2003Gupta authored Jun 30, 2023
1 parent c4e11bc commit d8294d2
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions python/podio/podio_config_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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: <type> <name> // <comment>")

return self._parse_with_regexps(string, default_matchers_cbs + no_desc_matchers_cbs)


class ClassDefinitionValidator:
Expand Down

0 comments on commit d8294d2

Please sign in to comment.