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
version test - improve message when value is empty #74754
version test - improve message when value is empty #74754
Conversation
When an empty value is provided, no `version` attribute will exist on the `LooseVersion` or `StrictVersion` object. We catch and handle this, but it's not immediatebly clear that an AttributeError means an empty value was provided. Handle this case specifically and add a more helpful error message. Add unit and integration tests.
@@ -168,6 +168,9 @@ def version_compare(value, version, operator='eq', strict=None, version_type=Non | |||
if strict is not None and version_type is not None: | |||
raise errors.AnsibleFilterError("Cannot specify both 'strict' and 'version_type'") | |||
|
|||
if not value: |
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 think we need to check both version
and value
. Otherwise just catch the AttributeError
in the below try/except and give this error 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.
Both should be checked.
Do we want one error message, or a separate error message for each combination (value, version, both)?
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.
Catching the AttributeError
was the first approach I took. Then I switched to failing early by checking up front. I didn't think about checking both value
and version
, though.
I'll just test both here and adjust the error message.
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 went with separate error messages for both. The language was too ambiguous trying to cram it into one message.
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'm open to feedback on the language. It's tough trying to communicate the input version value versus the version comparison value. They're both version comparison values. 🤯
@@ -168,6 +168,9 @@ def version_compare(value, version, operator='eq', strict=None, version_type=Non | |||
if strict is not None and version_type is not None: | |||
raise errors.AnsibleFilterError("Cannot specify both 'strict' and 'version_type'") | |||
|
|||
if not value: |
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.
Both should be checked.
Do we want one error message, or a separate error message for each combination (value, version, both)?
Add different error messages for each. Not handling the scenario if both are empty for now. Update integration tests.
…ible#74754) When an empty value is provided, no `version` attribute will exist on the `LooseVersion` or `StrictVersion` object. We catch and handle this, but it's not immediatebly clear that an AttributeError means an empty value was provided. Specifically handle the case where value or version are empty and add more helpful error messages. Add integration tests. (cherry picked from commit 71e33d2) Co-authored-by: Sam Doran <sdoran@redhat.com>
) (#74789) When an empty value is provided, no `version` attribute will exist on the `LooseVersion` or `StrictVersion` object. We catch and handle this, but it's not immediatebly clear that an AttributeError means an empty value was provided. Specifically handle the case where value or version are empty and add more helpful error messages. Add integration tests. (cherry picked from commit 71e33d2) Co-authored-by: Sam Doran <sdoran@redhat.com>
SUMMARY
When an empty value is provided, no
version
attribute will exist on theLooseVersion
orStrictVersion
object. We catch and handle this, but it's not immediatebly clear to the non-Python programmer that anAttributeError
means an empty value was provided to the test.Handle this case specifically and add a more helpful error message.
Add unit and integration tests.
ISSUE TYPE
COMPONENT NAME
lib/ansible/plugins/test/core.py