Skip to content

Commit 886064a

Browse files
Clarify invalid session timestamp string diagnostics
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent eb2e113 commit 886064a

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

hyperbrowser/models/session.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,12 @@ def parse_timestamp(cls, value: Optional[Union[str, int]]) -> Optional[int]:
149149
"timestamp values must be integers or plain numeric strings"
150150
)
151151
if type(value) is str:
152-
return int(value)
152+
try:
153+
return int(value)
154+
except Exception as exc:
155+
raise ValueError(
156+
"timestamp string values must be integer-formatted"
157+
) from exc
153158
if isinstance(value, str):
154159
raise ValueError("timestamp string values must be plain strings")
155160
return value

tests/test_session_models.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,13 @@ def test_session_model_preserves_integer_timestamps():
6060

6161
assert model.start_time == 1735689600
6262
assert model.end_time == 1735689660
63+
64+
65+
def test_session_model_rejects_non_integer_timestamp_strings():
66+
payload = _build_session_payload()
67+
payload["startTime"] = "not-a-number"
68+
69+
with pytest.raises(
70+
ValidationError, match="timestamp string values must be integer-formatted"
71+
):
72+
Session.model_validate(payload)

0 commit comments

Comments
 (0)