Skip to content

#378 Get a nice error message when running diff-quality with a tool which is not installed - #380

Merged
Bachmann1234 merged 3 commits into
Bachmann1234:mainfrom
d-perl:378_fix_error_message
Dec 16, 2023
Merged

Bachmann1234 merged 3 commits into
Bachmann1234:mainfrom
d-perl:378_fix_error_message

Conversation

@d-perl

@d-perl d-perl commented Dec 13, 2023

Copy link
Copy Markdown
Contributor

Fixes #378

To test, compare with "steps to reproduce" in the linked issue

@d-perl
d-perl force-pushed the 378_fix_error_message branch from a0b744a to 59fed0c Compare December 13, 2023 15:23
Black is upset, looks like the change is simple enough
@Bachmann1234

Copy link
Copy Markdown
Owner

ok, quick glance looks like some tests broke. My guess is its some mocking that broke. Let me know if you need some help looking a bit deeper

@Bachmann1234

Copy link
Copy Markdown
Owner

Also, hope you dont mind my commit, I just wanted to get past the formatting step

@d-perl

d-perl commented Dec 14, 2023

Copy link
Copy Markdown
Contributor Author

Oh, my bad. It was because shell=True doesn't pass along the (virtual) environment, so the various tools aren't necessarily installed. I've updated it to use the more explicit exception handling which is recommended in the python docs anyway; tests pass for me locally now.

@Bachmann1234

Copy link
Copy Markdown
Owner

Alright, lets get this out. Thanks for the PR!

@Bachmann1234
Bachmann1234 merged commit d6ec6af into Bachmann1234:main Dec 16, 2023
Bachmann1234 pushed a commit that referenced this pull request Aug 16, 2026
…620)

* fix: report a missing git instead of an unhandled FileNotFoundError (#303)

subprocess.Popen sits outside the try in command_runner.execute, so when the
executable itself is missing the FileNotFoundError escapes raw. Both entry
points call GitPathTool.set_cwd before their own error handling begins --
diff_quality_tool.main already has `except OSError -> LOGGER.error -> return 1`
further down, it simply never gets the chance to run -- so `diff-cover` and
`diff-quality` print a traceback when git is not installed.

Add ExecutableNotFoundError as a subclass of CommandError, so anything that
already catches CommandError keeps working, and raise it from execute() only
for the FileNotFoundError that Popen throws. A command that runs and then
fails is untouched: tests/test_integration.py requires CommandError to escape
main() in that case, and it still does.

Both main() functions now wrap set_cwd and report the message through
LOGGER.error, returning 1.

This is the same class of fix as #380 for #378, which covered the "the linter
is not installed" path through run_command_for_code; the "git is not
installed" path through execute was left as it was.

* test: assert on the install URL without a substring check

CodeQL flagged `assert "https://git-scm.com/" in message` as
py/incomplete-url-substring-sanitization. The rule is about URL checks done
with substring containment, and a test assertion is written the same way as
the pattern it warns about.

Import GIT_INSTALL_URL and assert on the whole trailing sentence instead,
which is a stricter assertion anyway, and use the constant for the negative
case as well.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Running diff-quality with a tool which is not installed gives FIleNotFoundError rather than helpful "<tool> is not installed" error message

2 participants