Skip to content
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

Merged
merged 3 commits into from May 20, 2021

Conversation

samdoran
Copy link
Contributor

SUMMARY

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 to the non-Python programmer that an AttributeError 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
  • Bugfix Pull Request
COMPONENT NAME

lib/ansible/plugins/test/core.py

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.
@samdoran samdoran requested a review from mattclay May 18, 2021 20:09
@ansibot ansibot added affects_2.12 bug This issue/PR relates to a bug. core_review In order to be merged, this PR must follow the core review workflow. needs_triage Needs a first human triage before being processed. new_plugin This PR includes a new plugin. support:community This issue/PR relates to code supported by the Ansible community. support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels May 18, 2021
@@ -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:
Copy link
Member

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.

Copy link
Member

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)?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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:
Copy link
Member

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)?

test/units/plugins/filter/core/test_version_compare.py Outdated Show resolved Hide resolved
@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed core_review In order to be merged, this PR must follow the core review workflow. labels May 18, 2021
Add different error messages for each. Not handling the scenario if both are empty for now.
Update integration tests.
@ansibot ansibot added core_review In order to be merged, this PR must follow the core review workflow. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. core_review In order to be merged, this PR must follow the core review workflow. labels May 19, 2021
@mattclay mattclay removed the needs_triage Needs a first human triage before being processed. label May 19, 2021
@ansibot ansibot added core_review In order to be merged, this PR must follow the core review workflow. and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels May 19, 2021
@samdoran samdoran merged commit 71e33d2 into ansible:devel May 20, 2021
@samdoran samdoran deleted the version-test-empty-value-error branch May 20, 2021 15:55
samdoran added a commit to samdoran/ansible that referenced this pull request May 21, 2021
…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>
relrod pushed a commit that referenced this pull request Jun 11, 2021
) (#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>
@ansible ansible locked and limited conversation to collaborators Jun 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.12 bug This issue/PR relates to a bug. core_review In order to be merged, this PR must follow the core review workflow. new_plugin This PR includes a new plugin. support:community This issue/PR relates to code supported by the Ansible community. support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants