Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions hyperbrowser/client/managers/sandboxes/process_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,20 @@ def __init__(self, process_id: str, max_bytes: int):
}

def failure(
self, message: str, code: str = "incomplete_output"
self,
message: str,
code: str = "incomplete_output",
details: Optional[Dict[str, int]] = None,
) -> HyperbrowserError:
return HyperbrowserError(
message,
code=code,
service="runtime",
details={"process_id": self.process_id, "last_seq": self.seq},
details={
"process_id": self.process_id,
"last_seq": self.seq,
**(details or {}),
},
)

def consume(self, event) -> None:
Expand All @@ -51,8 +58,9 @@ def consume(self, event) -> None:
self.size += len(raw)
if self.size > self.max_bytes:
raise self.failure(
"Command output exceeds max_output_bytes; increase the collection limit or disconnect a detached process",
f"Command output exceeds max_output_bytes ({self.size} bytes received, limit {self.max_bytes}); increase the collection limit or disconnect a detached process",
"output_limit_exceeded",
{"max_output_bytes": self.max_bytes, "received_bytes": self.size},
)
self.seq = data["seq"]
text = self._decoders[stream].decode(raw)
Expand Down
10 changes: 10 additions & 0 deletions tests/test_sandbox_process_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,13 @@ def test_invalid_collection_limit_rejected_before_start(limit):
with pytest.raises(ValueError, match="positive integer"):
SyncProcesses(transport).start("test", max_output_bytes=limit)
assert not transport.calls


def test_output_limit_error_reports_limit_and_received_bytes():
transport = SyncTransport([output(1, b"too much"), done(1)])
with pytest.raises(HyperbrowserError) as exc:
SyncProcesses(transport).exec("test", max_output_bytes=4)
assert exc.value.code == "output_limit_exceeded"
assert exc.value.details["max_output_bytes"] == 4
assert exc.value.details["received_bytes"] == 8
assert "8 bytes received, limit 4" in str(exc.value)