Skip to content

Commit

Permalink
Avoid crashing when the user has no homedir
Browse files Browse the repository at this point in the history
  • Loading branch information
Joachim Jablon committed Jan 27, 2022
1 parent b92822a commit acb288d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -43,6 +43,7 @@
- Work around bug that causes unstable formatting in some cases in the presence of the
magic trailing comma (#2807)
- Deprecate the `black-primer` tool (#2809)
- Avoid crashing when the user has no homedir (#2813)

### Packaging

Expand Down
6 changes: 5 additions & 1 deletion src/black/files.py
Expand Up @@ -87,7 +87,7 @@ def find_pyproject_toml(path_search_start: Tuple[str, ...]) -> Optional[str]:
if path_user_pyproject_toml.is_file()
else None
)
except PermissionError as e:
except (PermissionError, RuntimeError) as e:
# We do not have access to the user-level config directory, so ignore it.
err(f"Ignoring user configuration directory due to {e!r}")
return None
Expand All @@ -111,6 +111,10 @@ def find_user_pyproject_toml() -> Path:
This looks for ~\.black on Windows and ~/.config/black on Linux and other
Unix systems.
May raise:
- RuntimeError: if the current user has no homedir
- PermissionError: if the current process cannot access the user's homedir
"""
if sys.platform == "win32":
# Windows
Expand Down

0 comments on commit acb288d

Please sign in to comment.