Skip to content

Commit 99ce252

Browse files
Require concrete polling exception text render outputs
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 78150be commit 99ce252

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

hyperbrowser/client/polling.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,15 @@ def _safe_exception_text(exc: Exception) -> str:
3737
exception_message = str(exc)
3838
except Exception:
3939
return f"<unstringifiable {type(exc).__name__}>"
40-
if not isinstance(exception_message, str):
40+
if type(exception_message) is not str:
4141
return f"<unstringifiable {type(exc).__name__}>"
4242
try:
4343
sanitized_exception_message = "".join(
4444
"?" if ord(character) < 32 or ord(character) == 127 else character
4545
for character in exception_message
4646
)
47+
if type(sanitized_exception_message) is not str:
48+
return f"<unstringifiable {type(exc).__name__}>"
4749
if sanitized_exception_message.strip():
4850
if len(sanitized_exception_message) <= _MAX_EXCEPTION_TEXT_LENGTH:
4951
return sanitized_exception_message

tests/test_polling.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6923,6 +6923,31 @@ def __str__(self) -> str:
69236923
)
69246924

69256925

6926+
def test_poll_until_terminal_status_handles_runtime_errors_with_string_subclass_results():
6927+
class _RenderedRuntimeError(RuntimeError):
6928+
class _RenderedString(str):
6929+
pass
6930+
6931+
def __str__(self) -> str:
6932+
return self._RenderedString("runtime subclass text")
6933+
6934+
with pytest.raises(
6935+
HyperbrowserPollingError,
6936+
match=(
6937+
r"Failed to poll sync poll after 1 attempts: "
6938+
r"<unstringifiable _RenderedRuntimeError>"
6939+
),
6940+
):
6941+
poll_until_terminal_status(
6942+
operation_name="sync poll",
6943+
get_status=lambda: (_ for _ in ()).throw(_RenderedRuntimeError()),
6944+
is_terminal_status=lambda value: value == "completed",
6945+
poll_interval_seconds=0.0,
6946+
max_wait_seconds=1.0,
6947+
max_status_failures=1,
6948+
)
6949+
6950+
69266951
def test_retry_operation_handles_unstringifiable_value_errors():
69276952
class _UnstringifiableValueError(ValueError):
69286953
def __str__(self) -> str:

0 commit comments

Comments
 (0)