Skip to content

fix: handle OSError in pos_args path existence check#3847

Merged
gaborbernat merged 2 commits intotox-dev:mainfrom
yarikoptic:bf-posargs-long-path
Mar 3, 2026
Merged

fix: handle OSError in pos_args path existence check#3847
gaborbernat merged 2 commits intotox-dev:mainfrom
yarikoptic:bf-posargs-long-path

Conversation

@yarikoptic
Copy link
Copy Markdown
Contributor

When positional arguments exceed the filesystem's filename length limit (typically 255 characters), Path.exists() raises OSError: [Errno 36] File name too long instead of returning False.

This causes tox to crash with an internal error when long -k expressions are passed via {posargs}, e.g.:

tox -e py3 -- -k "test_foo or test_bar or test_baz or ..."

The traceback is:

File ".../tox/config/main.py", line 58, in pos_args
    if path_arg.exists() and not path_arg.is_absolute():
OSError: [Errno 36] File name too long: 'test_foo or test_bar or ...'

This is because pos_args() checks each argument with path_arg.exists() to determine whether to rewrite relative paths for changedir. An argument that is too long for the filesystem clearly cannot be a path, so the fix catches OSError and treats such arguments as non-paths.

  • ran the linter to address style issues (tox -e fix) [XXX]
  • wrote descriptive pull request text
  • ensured there are test(s) validating the fix
  • added news fragment in docs/changelog folder --
  • updated/extended the documentation
[XXX]: tried but failed to install sphinx... might try again later
[INFO] Using pre-commit with uv 0.10.7 via pre-commit-uv 4.2.1
An unexpected error has occurred: CalledProcessError: command: ('/home/yoh/proj/misc/tox/.tox/fix/bin/uv', '--project', '/home/yoh/proj/misc/tox', 'pip', 'install', '.', 'sphinx>=9.1')
return code: 1
stdout: (none)
stderr:
    Using Python 3.11.12 environment at: py_env-python3
      × No solution found when resolving dependencies:
      ╰─▶ Because the current Python version (3.11.12) does not satisfy
          Python>=3.12 and sphinx==9.1.0 depends on Python>=3.12, we can conclude
          that sphinx==9.1.0 cannot be used.
          And because only sphinx<=9.1.0 is available and you require sphinx>=9.1,
          we can conclude that your requirements are unsatisfiable.
Check the log at /home/yoh/.cache/pre-commit/pre-commit.log
fix: exit 3 (24.65 seconds) /home/yoh/proj/misc/tox> pre-commit run --all-files --show-diff-on-failure pid=4127791
  fix: FAIL code 3 (25.28=setup[0.62]+cmd[24.65] seconds)
  evaluation failed :( (25.34 seconds)

When positional arguments exceed the filesystem's filename length limit
(typically 255 characters), `Path.exists()` raises `OSError: [Errno 36]
File name too long` instead of returning `False`.

This causes `tox` to crash with an internal error when long `-k`
expressions are passed via `{posargs}`, e.g.:

    tox -e py3 -- -k "test_foo or test_bar or test_baz or ..."

The traceback is:

    File ".../tox/config/main.py", line 58, in pos_args
        if path_arg.exists() and not path_arg.is_absolute():
    OSError: [Errno 36] File name too long: 'test_foo or test_bar or ...'

This is because `pos_args()` checks each argument with `path_arg.exists()`
to determine whether to rewrite relative paths for `changedir`. An argument
that is too long for the filesystem clearly cannot be a path, so the fix
catches `OSError` and treats such arguments as non-paths.

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
@gaborbernat gaborbernat merged commit 9aaec0c into tox-dev:main Mar 3, 2026
27 checks passed
@yarikoptic
Copy link
Copy Markdown
Contributor Author

that was quick -- kudos!

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.

2 participants