Skip to content

Commit 2989f22

Browse files
Simplify file-path error helper default prefix handling
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 4290d88 commit 2989f22

4 files changed

Lines changed: 15 additions & 7 deletions

File tree

hyperbrowser/client/file_utils.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
22
from contextlib import contextmanager
33
from os import PathLike
4-
from typing import BinaryIO, Iterator, Union
4+
from typing import BinaryIO, Iterator, Optional, Union
55

66
from hyperbrowser.exceptions import HyperbrowserError
77
from hyperbrowser.type_utils import is_plain_int, is_plain_string
@@ -76,9 +76,12 @@ def build_file_path_error_message(
7676
file_path: object,
7777
*,
7878
prefix: str,
79-
default_prefix: str,
79+
default_prefix: Optional[str] = None,
8080
) -> str:
81-
normalized_prefix = _normalize_error_prefix(prefix, default_prefix=default_prefix)
81+
normalized_prefix = _normalize_error_prefix(
82+
prefix,
83+
default_prefix=prefix if default_prefix is None else default_prefix,
84+
)
8285
file_path_display = format_file_path_for_error(file_path)
8386
return f"{normalized_prefix}: {file_path_display}"
8487

hyperbrowser/client/managers/extension_create_utils.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,10 @@ def normalize_extension_create_input(params: Any) -> Tuple[str, Dict[str, Any]]:
3131
missing_file_message=build_file_path_error_message(
3232
raw_file_path,
3333
prefix="Extension file not found at path",
34-
default_prefix="Extension file not found at path",
3534
),
3635
not_file_message=build_file_path_error_message(
3736
raw_file_path,
3837
prefix="Extension file path must point to a file",
39-
default_prefix="Extension file path must point to a file",
4038
),
4139
)
4240
return file_path, payload

hyperbrowser/client/managers/session_upload_utils.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,10 @@ def normalize_upload_file_input(
3232
missing_file_message=build_file_path_error_message(
3333
raw_file_path,
3434
prefix="Upload file not found at path",
35-
default_prefix="Upload file not found at path",
3635
),
3736
not_file_message=build_file_path_error_message(
3837
raw_file_path,
3938
prefix="Upload file path must point to a file",
40-
default_prefix="Upload file path must point to a file",
4139
),
4240
)
4341
return file_path, None

tests/test_file_utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,15 @@ def test_build_file_path_error_message_uses_prefix_and_sanitized_path():
342342
assert message == "Upload file not found at path: bad?path.txt"
343343

344344

345+
def test_build_file_path_error_message_defaults_default_prefix_to_prefix():
346+
message = build_file_path_error_message(
347+
"bad\tpath.txt",
348+
prefix="Upload file not found at path",
349+
)
350+
351+
assert message == "Upload file not found at path: bad?path.txt"
352+
353+
345354
def test_build_file_path_error_message_uses_default_for_non_string_prefix():
346355
message = build_file_path_error_message(
347356
"/tmp/path.txt",

0 commit comments

Comments
 (0)