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

Make git errors fatal when strict mode is active #3064

Merged
merged 1 commit into from
Mar 1, 2023
Merged

Conversation

ssbarnea
Copy link
Member

Fixes: #3062

@ssbarnea ssbarnea requested a review from a team as a code owner February 18, 2023 16:18
@github-actions github-actions bot added the skip-changelog Can be missed from the changelog. label Feb 18, 2023
@kpfleming
Copy link

Hmm... I can't reproduce the original problem using this branch, because the changes made for #2890 stop Git from generating the error I saw originally.

Instead I just 'broke' the repo clone so that Git would report errors when running ls-files. With that in place, using this branch and --strict, this is the result:

(lint-test-venv) kpfleming@balrog22:~/git-personal/ansible-systemd-networkd$ ansible-lint -v --strict
INFO     Set ANSIBLE_LIBRARY=/home/kpfleming/.cache/ansible-compat/988886/modules:/home/kpfleming/.ansible/plugins/modules:/usr/share/ansible/plugins/modules
INFO     Set ANSIBLE_COLLECTIONS_PATH=/home/kpfleming/.cache/ansible-compat/988886/collections:/home/kpfleming/.ansible/collections:/usr/share/ansible/collections
INFO     Set ANSIBLE_ROLES_PATH=/home/kpfleming/.cache/ansible-compat/988886/roles:/home/kpfleming/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles
WARNING  Failed to discover lintable files using git: fatal: .git/index: index file open failed: Permission denied
Traceback (most recent call last):
  File "/home/kpfleming/git-personal/lint-test-venv/bin/ansible-lint", line 8, in <module>
    sys.exit(_run_cli_entrypoint())
             ^^^^^^^^^^^^^^^^^^^^^
  File "/home/kpfleming/git-personal/lint-test-venv/lib/python3.11/site-packages/ansiblelint/__main__.py", line 360, in _run_cli_entrypoint
    sys.exit(main(sys.argv))
             ^^^^^^^^^^^^^^
  File "/home/kpfleming/git-personal/lint-test-venv/lib/python3.11/site-packages/ansiblelint/__main__.py", line 250, in main
    result = _get_matches(rules, options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kpfleming/git-personal/lint-test-venv/lib/python3.11/site-packages/ansiblelint/runner.py", line 216, in _get_matches
    lintables = ansiblelint.utils.get_lintables(opts=options, args=options.lintables)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kpfleming/git-personal/lint-test-venv/lib/python3.11/site-packages/ansiblelint/utils.py", line 848, in get_lintables
    for filename in discover_lintables(opts):
                    ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kpfleming/git-personal/lint-test-venv/lib/python3.11/site-packages/ansiblelint/file_utils.py", line 420, in discover_lintables
    out_present = subprocess.check_output(
                  ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/python-3.11.2/lib/python3.11/subprocess.py", line 466, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/python-3.11.2/lib/python3.11/subprocess.py", line 571, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['git', '-c', 'safe.directory=/home/kpfleming/git-personal/ansible-systemd-networkd', 'ls-files', '--cached', '--others', '--exclude-standard', '-z']' returned non-zero exit status 128.

Without --strict ansible-lint falls back to the non-Git-based method of finding lintables, as expected.

Copy link
Contributor

@cidrblock cidrblock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's sys.exit(1) with a logger error and w/o a traceback

@ssbarnea ssbarnea marked this pull request as ready for review March 1, 2023 11:53
@ssbarnea ssbarnea merged commit 8844e7b into main Mar 1, 2023
@ssbarnea ssbarnea deleted the chore/deps branch March 1, 2023 12:13
@ssbarnea ssbarnea added bug and removed skip-changelog Can be missed from the changelog. labels Mar 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

--strict does not convert WARNING during Lintables discovery into an ERROR
4 participants