Skip to content

Commit 4c58b77

Browse files
Clarify response parser key-read failures
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 2962511 commit 4c58b77

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

hyperbrowser/client/managers/response_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def parse_response_model(
6161
raise
6262
except Exception as exc:
6363
raise HyperbrowserError(
64-
f"Failed to read {normalized_operation_name} response data",
64+
f"Failed to read {normalized_operation_name} response keys",
6565
original_error=exc,
6666
) from exc
6767
for key in response_keys:

tests/test_response_utils.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ def test_parse_response_model_truncates_operation_name_in_errors():
226226
def test_parse_response_model_wraps_mapping_read_failures():
227227
with pytest.raises(
228228
HyperbrowserError,
229-
match="Failed to read basic operation response data",
229+
match="Failed to read basic operation response keys",
230230
) as exc_info:
231231
parse_response_model(
232232
_BrokenMapping({"success": True}),
@@ -237,6 +237,27 @@ def test_parse_response_model_wraps_mapping_read_failures():
237237
assert exc_info.value.original_error is not None
238238

239239

240+
def test_parse_response_model_preserves_hyperbrowser_key_read_failures():
241+
class _BrokenMapping(Mapping[str, object]):
242+
def __iter__(self):
243+
raise HyperbrowserError("custom key read failure")
244+
245+
def __len__(self) -> int:
246+
return 1
247+
248+
def __getitem__(self, key: str) -> object:
249+
return key
250+
251+
with pytest.raises(HyperbrowserError, match="custom key read failure") as exc_info:
252+
parse_response_model(
253+
_BrokenMapping(),
254+
model=BasicResponse,
255+
operation_name="basic operation",
256+
)
257+
258+
assert exc_info.value.original_error is None
259+
260+
240261
def test_parse_response_model_wraps_mapping_value_read_failures():
241262
with pytest.raises(
242263
HyperbrowserError,

0 commit comments

Comments
 (0)