Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Make error message from parsing more explicit #437

Merged
merged 7 commits into from
Jun 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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