-
Notifications
You must be signed in to change notification settings - Fork 989
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
Add more meaninful error when parsing conanfile reference (closes #3204) #3410
Conversation
conans/model/ref.py
Outdated
@@ -4,11 +4,23 @@ | |||
from conans.model.version import Version | |||
|
|||
|
|||
# TODO: Move to some tools module |
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.
Let me know if I leave this code here or move to conans/utils
module.... or maybe use a six approach:
from six import string_types
isinstance(s, string_types)
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.
Yes, use six tools, please.
conans/model/ref.py
Outdated
class ConanName(object): | ||
_max_chars = 50 | ||
_min_chars = 2 | ||
_validation_pattern = re.compile("^[a-zA-Z0-9_][a-zA-Z0-9_\+\.-]{%s,%s}$" | ||
% (_min_chars - 1, _max_chars)) | ||
% (_min_chars - 1, _max_chars - 1)) |
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.
This is breaking! Should we change _max_chars = 51
too?
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.
Could you add some test checking the length limit of the names (or add a new one checking the upper limit)?
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.
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 would say yes, we should raise it to 51
conans/model/ref.py
Outdated
if name == "*": | ||
return | ||
if ConanName._validation_pattern.match(name) is None: | ||
if version and name.startswith("[") and name.endswith("]"): | ||
# TODO: Check value between brackets |
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.
Leave it as TODO or check version ranges according to semver as documented (https://docs.conan.io/en/latest/mastering/version_ranges.html)?
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.
Could be done in a different PR, not urgent, leave it.
Related stuff (maybe for a different PR):
Work ongoing: #3444 |
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 don't think this PR is related to #3204.
Not sure if this is the right approach. The original issue is about the version
field in conanfile.py, not about the allowed values in ConanFileReference
. I would add a check before it is passed to this ConanFileReference
class, not such extensive checking inside ConanFileReference
. Just an opinion, need to check further.
conans/model/ref.py
Outdated
@@ -4,11 +4,23 @@ | |||
from conans.model.version import Version | |||
|
|||
|
|||
# TODO: Move to some tools module |
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.
Yes, use six tools, please.
I think that it is ok to centralize here all these checks, but I agree that the message can be more explicit so the user knows where the error comes from. Take a look to the last commit, now the message for the error reported by @ovidiub13 would be:
|
conans/model/ref.py
Outdated
ConanName.validate_name(user) | ||
ConanName.validate_name(channel) | ||
message = "Value provided for {item}, '{{value}}' (type {{type}}), {{reason}}" | ||
ConanName.validate_name(name, message=message.format(item="package name")) |
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.
Do not format every argument (this operation might be done lots of times), for every new ConanFileReference you are formating 4 strings. I know it seems little, but we need to try to keep performance and running time low.
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.
Ok, then I'll go for a different approach
conans/model/ref.py
Outdated
ConanName.invalid_name_message(username) | ||
def validate_string(value, message=None): | ||
"""Check for string""" | ||
if not isinstance(value, string_types): |
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 don't like this checking for string, too defensive. All the fields of ConanFileReference are strings, by definition.
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.
This issue started because we want to provide a more meaninful message for a version = 1.0
(number) inside a conanfile.py
... and we didn't want to make an implicit conversion to string. So I think we do need to check for string type (or handle the exception if the regex fails).
conans/model/ref.py
Outdated
class ConanName(object): | ||
_max_chars = 50 | ||
_min_chars = 2 | ||
_validation_pattern = re.compile("^[a-zA-Z0-9_][a-zA-Z0-9_\+\.-]{%s,%s}$" | ||
% (_min_chars - 1, _max_chars)) | ||
% (_min_chars - 1, _max_chars - 1)) |
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 would say yes, we should raise it to 51
conans/model/ref.py
Outdated
if name == "*": | ||
return | ||
if ConanName._validation_pattern.match(name) is None: | ||
if version and name.startswith("[") and name.endswith("]"): | ||
# TODO: Check value between brackets |
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.
Could be done in a different PR, not urgent, leave it.
…an-io#3204) (conan-io#3410) * check that parameters are string before applying regex match * add tests related to ConanName * typo * update docs related to function * use six to check for string types * use a custom message to validate each field * refactor tests to validate custom messages * fix tests: message is more explicit * given conan-io#3464 this is dead code * format error message only if we are actually going to use it * minor changes: address @lasote review
Handles error described in #3204 to provide a more meaninful error:
ERROR: '1.0' is not an string
Changelog: Fix: Improved error message when parsing a bad conanfile reference.