Skip to content

Handle unreadable configuration files - #4035

Merged
gaborbernat merged 2 commits into
tox-dev:mainfrom
SirHegel:handle-unreadable-config-files
Aug 20, 2026
Merged

Handle unreadable configuration files#4035
gaborbernat merged 2 commits into
tox-dev:mainfrom
SirHegel:handle-unreadable-config-files

Conversation

@SirHegel

Copy link
Copy Markdown
Contributor

Fixes #4031.

The problem

The three source-loading paths in tox.config.source.discover translate ValueError into HandledError, but reading a file can also raise an OSError subclass. So a config file that exists and cannot be read lets PermissionError escape:

$ chmod 000 tox.ini
$ tox -c tox.ini list
Traceback (most recent call last):
  ...
PermissionError: [Errno 13] Permission denied: 'tox.ini'

After:

$ tox -c tox.ini list
ROOT: HandledError| ToxIni failed loading /tmp/p/tox.ini due to [Errno 13] Permission denied: 'tox.ini'

The change

OSError is caught alongside ValueError in all three paths — the directory branch of discover_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_source directly rather than going through the tox_project fixture.

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 loading line and the test cannot tell them apart. Testing the function where the bug lives does distinguish them: unfixed it raises PermissionError, fixed it raises HandledError.

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.

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.
@gaborbernat
gaborbernat merged commit cc93509 into tox-dev:main Aug 20, 2026
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unreadable configuration files leak an OSError traceback

2 participants