Skip to content

Commit b20aa0d

Browse files
Improve invalid file path type diagnostics
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent b61707d commit b20aa0d

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

‎hyperbrowser/client/file_utils.py‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ def ensure_existing_file_path(
1111
missing_file_message: str,
1212
not_file_message: str,
1313
) -> str:
14-
normalized_path = os.fspath(file_path)
14+
try:
15+
normalized_path = os.fspath(file_path)
16+
except TypeError as exc:
17+
raise HyperbrowserError(
18+
"file_path must be a string or os.PathLike object",
19+
original_error=exc,
20+
) from exc
1521
if not os.path.exists(normalized_path):
1622
raise HyperbrowserError(missing_file_message)
1723
if not os.path.isfile(normalized_path):

‎tests/test_file_utils.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,14 @@ def test_ensure_existing_file_path_raises_for_directory(tmp_path: Path):
5050
missing_file_message="missing",
5151
not_file_message="not-file",
5252
)
53+
54+
55+
def test_ensure_existing_file_path_rejects_invalid_path_type():
56+
with pytest.raises(
57+
HyperbrowserError, match="file_path must be a string or os.PathLike object"
58+
):
59+
ensure_existing_file_path(
60+
123, # type: ignore[arg-type]
61+
missing_file_message="missing",
62+
not_file_message="not-file",
63+
)

0 commit comments

Comments
 (0)