Report a bad ini core value as a handled error - #4028
Open
VXNCXNX wants to merge 2 commits into
Open
Conversation
The ini loader called self.to() unguarded, so a conversion failure on a [tox] core value escaped as a raw traceback. The TOML loader already wraps the same call and raises HandledError, so identical input gave a clean message in pyproject.toml but a traceback in tox.ini.
for more information, see https://pre-commit.ci
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A bad value in the ini
[tox]core section exits with a raw traceback, while the same value inpyproject.tomlis already reported properly.The TOML path, same input, unchanged by this PR:
After:
requires = ===bad!!!andenv_list = {py39,py310(unbalanced brace) were tracebacks too, and are now handled the same way.The fix
IniLoader.buildcalledself.to(...)unguarded.TomlLoader.buildalready wraps the identical call and re-raises asHandledError, so this mirrors it, including lettingHandledErrorandSkipthrough untouched.Why the guard is narrow
The wrap only applies to the core section. My first attempt covered every section and broke 6 existing tests, because two paths deliberately let raw exceptions through:
tox crenders the exception inline as# Exception: ...(test_config_bad_dict,test_config_bad_booland friends)conf is NoneThose are existing behaviour I did not want to change, so the condition is
conf is None or args.env_name is not Noneto bypass. Core values are the case with no handling at all, because they are loaded before any guard is in place.Verification
test_ini_core_bad_value_is_handled_errorintests/config/source/test_discover.py, parametrised overmin_version,requiresandenv_list. It asserts no unhandled exception leaks, so it fails on the actual symptom rather than on a message string.Reverting only the guard condition to always bypass fails it as an assertion:
pytest tests/config/is 6644 passed, 2 skipped.tests/config/cli/test_argcomplete.pyis excluded becauseargcompleteis not installed here; it fails to collect identically on a clean checkout.Disclosure: written with AI assistance (Claude Code). I reproduced the traceback and the TOML contrast at the CLI, confirmed the narrow guard is required by removing it and watching 6 tests break, and ran the mutation check myself.