Handle unreadable configuration files - #4035
Merged
gaborbernat merged 2 commits intoAug 20, 2026
Merged
Conversation
Fixes tox-dev#4031. The three source-loading paths in tox.config.source.discover translate ValueError into HandledError, but reading a file can also raise an OSError subclass. A config file that exists and cannot be read - wrong permissions, a directory where a file was expected - lets PermissionError escape, and the CLI prints a full traceback instead of the one-line error it uses for malformed files. Catches OSError alongside ValueError in all three paths: the directory branch of discover_source, _locate_source, and _load_exact_source. Affects the named file, automatic discovery, and -c <directory> equally. The regression test exercises discover_source directly rather than going through the tox_project fixture. The fixture converts exceptions on its own, so through it both the fixed and unfixed code produce the same output and the test cannot tell them apart.
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.
Fixes #4031.
The problem
The three source-loading paths in
tox.config.source.discovertranslateValueErrorintoHandledError, but reading a file can also raise anOSErrorsubclass. So a config file that exists and cannot be read letsPermissionErrorescape:After:
The change
OSErroris caught alongsideValueErrorin all three paths — the directory branch ofdiscover_source,_locate_source, and_load_exact_source— so the named file, automatic discovery, and-c <directory>all behave the same. Verified all three by hand.A note on the test
The regression test exercises
discover_sourcedirectly rather than going through thetox_projectfixture.I wrote it through the fixture first, and it passed against unfixed code. The fixture converts exceptions on its own, so from the outside both versions produce the same
HandledError| ToxIni failed loadingline and the test cannot tell them apart. Testing the function where the bug lives does distinguish them: unfixed it raisesPermissionError, fixed it raisesHandledError.The test is skipped on Windows and when running as root, since neither can make a file unreadable this way.
tests/config/source/: 200 passed.