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

Improve feedback for fix, avoid a traceback with transform #4148

Merged
merged 7 commits into from May 13, 2024

Conversation

cidrblock
Copy link
Contributor

@cidrblock cidrblock commented May 10, 2024

When linting the following repo: https://github.com/anshulbehl/ilo-ansible-collection

If was found that if ANSIBLE_LINT_NODEPS was enabled to bypass the missing plugins and roles, the fixing of files would traceback and stop immediately.

This PR both improves the debug and error messages during fix as well as avoids the traceback so file processing can continue.

The messages were set as constants to limit tight coupling to messages in the tests.

Fixing may be able to be improved if further time was spent with the above repo in the future.

Note: The precommit ruff version was set to the latest to catch some errors found locally

Messages will now appear like this:

ERROR    Rule specific fix failed for: key-order/task roles/playbooks/UpdateService/update_firmware_through_install_set.yml:75
ERROR    'when'
Traceback (most recent call last):
  File "/home/bthornto/github/ansible-lint/src/ansiblelint/transformer.py", line 168, in _do_transforms
    match.rule.transform(match, file, data)
  File "/home/bthornto/github/ansible-lint/src/ansiblelint/rules/key_order.py", line 137, in transform
    task = task.pop(key)
                ^^^^^^^^^^^^^
  File "/home/bthornto/github/ansible-lint/venv/lib64/python3.12/site-packages/ruamel/yaml/comments.py", line 926, in pop
    result = self
             ~~~~^^^^^
  File "/home/bthornto/github/ansible-lint/venv/lib64/python3.12/site-packages/ruamel/yaml/comments.py", line 853, in __getitem__
    return ordereddict.__getitem__(self, key)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: 'when'
ERROR    Please file an issue for this with the task or playbook that caused the error.

@cidrblock cidrblock requested a review from ganeshrn May 10, 2024 17:47
@cidrblock cidrblock requested a review from a team as a code owner May 10, 2024 17:47
@cidrblock cidrblock requested review from ssbarnea and removed request for a team May 10, 2024 17:47
@github-actions github-actions bot added the bug label May 10, 2024
@ssbarnea ssbarnea merged commit c66c903 into ansible:main May 13, 2024
25 checks passed
ssbarnea added a commit that referenced this pull request May 13, 2024
ssbarnea added a commit that referenced this pull request May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

2 participants