Repository navigation
fix: raise FileNotFoundError from place_*_file on a missing drive - #639
Open
nk-batman21 wants to merge 1 commit into
Open
nk-batman21 wants to merge 1 commit into
nk-batman21 wants to merge 1 commit into
Conversation
_make_private_directories retried with path.parent on FileNotFoundError without stopping at the root. On Windows a missing drive or network share fails at its root, which is its own parent, so place_*_file ended in RecursionError instead of the FileNotFoundError that Path.mkdir(parents=True) and ensure_exists raise for the same path.
This branch has not been deployed
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.
place_config_file()and the otherplace_*_filemethods create missing parent directories through_make_private_directories, which retries withpath.parentwhenevermkdirraisesFileNotFoundError. When the root itself is missing, as with an unmounted drive letter or an unreachable network share on Windows, the root is its own parent, so the helper keeps calling itself until Python raisesRecursionError.To reproduce on Windows, set
WIN_PD_OVERRIDE_LOCAL_APPDATA=Z:\AppData\Localwith noZ:drive (the docs suggest these overrides for keeping large data on another drive) and callPlatformDirs("MyApp", "Acme").place_config_file("settings.toml"). On main this raisesRecursionError: maximum recursion depth exceeded, whileensure_exists=Trueon the same setup raisesFileNotFoundError: [WinError 3] ... 'Z:\\'. A roaming profile pointing at\\localhost\no-such-share\AppData\Roamingfails the same way.RecursionErroris not anOSError, so code that handles directory creation failures withexcept OSErrorcrashes, and the traceback never names the missing path.The change re-raises the
FileNotFoundErroronce the path is its own parent, the same checkPath.mkdir(parents=True)makes. Both examples now raiseFileNotFoundError([WinError 3]for the drive,[WinError 67]for the share).Ran:
tox -e 3.14on Windows (2042 passed, 350 skipped, diff coverage 100%) andpytest tests/test_api.pyon Linux (Python 3.12). The new test fails on main withRecursionErrorand passes with the fix.Ran: the drive and share examples above, before and after the change.
Checked: the ruff, codespell and docstrfmt pre-commit hooks,
tox -e typeandtowncrier check.