-
Notifications
You must be signed in to change notification settings - Fork 60
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
Misleading Error: Invalid Member Definition #436
Comments
Hi @Ananya2003Gupta, thanks for the detailed report. I agree that this can be a bit confusing, and it is also not explicitly stated in our documentation. Having had a brief look at the code that parses the YAML files I think it should be possible to fix this, but I am not yet entirely sure when I can get to that. In case you are in any way interested in having a go at this yourself, let me know, and I can put together some information about what I think would need to be done. |
Yes, I would love to work on this issue. |
Very nice :) Then let me try to explain the current situation as well as how I would solve this a bit. The exception you see in this case is raised here: podio/python/podio/podio_config_reader.py Lines 51 to 60 in c4e11bc
As you can see, this currently only checks whether any of the regexes in the The list of podio/python/podio/podio_config_reader.py Lines 86 to 99 in c4e11bc
This just puts together a list of possible matches that will be tried in order, until one of them matches or the error is raised. I am not sure it is possible to solve this issue in a really general way, but this specific issue could be solved in the following way:
In principle you could then also have a look at the unittests for the Let me know if you need more information or clarifications. |
I had a doubt. Is it really necessary to have comments for each member definition? Can't we set the |
Yes, that was a conscious choice to mandate to have a description for members of |
@staticmethod
def _parse_with_regexps(string, regexps_callbacks):
"""Parse the string using the passed regexps and corresponding callbacks that
take the match and return a MemberVariable from it"""
for rgx, callback in regexps_callbacks:
result = rgx.match(string)
if result:
return callback(result)
raise DefinitionError(f"'{string}' is not a valid member definition.")
def parse(self, string, require_description=True):
"""Parse the passed string"""
default_matchers_cbs = [
(self.full_array_re, self._full_array_conv),
(self.member_re, self._full_member_conv)
]
try:
return self._parse_with_regexps(string, default_matchers_cbs)
except DefinitionError:
if not require_description:
matchers_cbs = [
(self.bare_array_re, self._bare_array_conv),
(self.bare_member_re, self._bare_member_conv)
]
try:
return self._parse_with_regexps(string, matchers_cbs)
except DefinitionError:
raise DefinitionError("Check the syntax of the member definition.")
raise DefinitionError("Description (Comment after member definition) is missing.") I have given it an attempt. |
Can you open a pull request with these changes in place? It is easier to make suggestions and comments there (see our contribution guidelines for a brief description of how to do that in case you do not already know). You should be able to do In the code you posted, the |
I was testing the code myself and I did encounter one logical error. |
I think the logic should look something like this: def parse(self, string, require_description=True):
default_matchers_cbs = [
(self.full_array_re, self._full_array_conv),
(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:
self._parse_with_regexps(string, no_desc_matchers_cbs)
raise DefinitionError("...") # useful error message
return self._parse_with_regexps(string, default_matchers_cbs + no_desc_matchers_cbs)
|
Okay. |
OS version: Ubuntu 22.04.2
Reproduced by:
python ../python/podio_class_generator.py ../tests/datalayout.yaml ../Tmp data ROOT
Input:
datalayout.yaml
Error Message:
Error while generating the datamodel: 'float energy' is not a valid member definition
Issue:
The error message is misleading and does not accurately describe the root cause of the problem.
Analysis:
After thorough debugging and documentation review, it was discovered that the error was due to the absence of comments after each member definition.
Solution:
Adding comments to the member definitions resolved the error.
Correction:
Expected Behavior:
The error message should accurately reflect the issue, indicating that comments are required for each member definition.
Actual Behavior:
The error message is misleading and does not provide clear guidance on the root cause, leading to confusion during debugging.
Possible Solution:
Updating the error message to include information about the requirement of comments in each member definition to prevent confusion and provide more accurate troubleshooting guidance.
The text was updated successfully, but these errors were encountered: