-
-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improved error message for invalid comments #47
Conversation
When invalid comments are found in the assigment to the zcml variable (i.e. those prepended by whitespace in the same line), the recipe complains about "Invalid zcml" and a "package" which is named '#firstword' or (even worse, if the '#' is followed by whitespace) '#', and the rest of the comment is silently taken as package names as well. (issue 46) This change explicitly creates a hopefully much more useful error message.
Wouldn't it be fine to ignore the comments instead of raising an error? So this:
Perhaps print a warning, but I don't think even that is needed. |
@mauritsvanrees : We can't rely on anything sane to happen when a comment is prepended by whitespace; so we should abort the build with a good message. |
I expect that Or is |
|
Okay, I didn't know that. In that case, as I said, you are right. So raising an error is good and helpful here. I am not sure about the wording of the new error message though. I have this test zcml:
The error then becomes:
I'm not sure everyone will realise what you mean with the first column. Instead of "must start in first column" maybe: "comment sign must be the first character on the line"? To me that would be clearer. I don't feel strongly about this, just a suggestion. And I think only the first package after the comment-sign is relevant. At least I assume most users will not have I wondered if the same needs to be done for the |
Please start the tests on Jenkins:
|
raise ValueError('Invalid comment in zcml assignment' | ||
' (must start in first column; something like' | ||
' %(comment_snippet)r)' | ||
% locals()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit picking: why use locals()
here? Since the string only uses one variable, I would just say ...%r' % comment_snippet
or '{0!r}'.format(comment_snippet)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Call it lazyness; I'll do it like this most of the time. When logging, it's a comma instead of the %
sign. Also, it's more foolproof to use a dict than a simple variable (which could contain a tuple and make the whole thing fail). Last, it should still be pretty efficient.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concerning jenkins, I'll need some more guidance here. I clicked over to jenkins.plone.org, and I was logged in without any futher action with my Github acount, but I can't find that "Build with parameters" form. Is this the exact name?
On https://jenkins.plone.org/job/plone-4.3-python-2.7/lastCompletedBuild/testReport/, there is no link for plone.recipe.zope2instance.
I had a look at https://docs.plone.org/develop/coredev/docs/intro.html#jenkins-mr-roboto as well but couldn't find a hint there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For Jenkins, see http://jenkinsploneorg.readthedocs.io/en/latest/run-pull-request-jobs.html. The video is helpful.
Or look at the box 'Some checks haven’t completed yet' on the github page you are currently reading. It has direct links to the relevant Plone versions that need a Jenkins run.
... which is presented in the ValueError, to one whitespace-separated "word" only ('#word' or '# word'). Reordered the error message.
Currently, the value is simply split by whitespace; thus, the "package" cannot contain blanks, and we can't tell how many of the following words are part of the comment. If the zcml value one day would be split by lines only, we would be able to safely skip the end of the line, following the '#'. If the comment doesn't contain blanks, we can't know this; but the only way for a comment to contain blanks is splitting by lines. So we can safely accept the '#text with blanks' or '# text with blanks' "package" as a comment and skip it.
Instead of performing complicated checks of package names starting with '#' characters, we can quite as well make line comments work. The function nocomments_split first splits the value by line separators, and then removes everything after the '#' (see doctest).
With the nocomments_split function, the mentioned error message is not necessary anymore, since comments are weeded out above.
I found a better solution: instead of forging a hopefully helpful message, simply make line comments in the The function |
@mauritsvanrees: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it!
And it seems to work fine.
This solution would be useful for the eggs
option too, but that can be done in a later PR if you are up to it. I will gladly merge this one now. Thanks!
Can you make a PR for master too for the zcml?
@mauritsvanrees: Sorry for the delay. I just created the pull request #57 |
When invalid comments are found in the assigment to the zcml variable
(i.e. those prepended by whitespace in the same line), the recipe
complains about "Invalid zcml" and a "package" which is named
'#firstword' or (even worse, if the '#' is followed by whitespace) '#',
and the rest of the comment is silently taken as package names as well.
(issue 46)
This change explicitly creates a hopefully much more useful error
message.