diff --git a/hyperbrowser/client/managers/sandboxes/process_output.py b/hyperbrowser/client/managers/sandboxes/process_output.py index ff1524e0..3184473e 100644 --- a/hyperbrowser/client/managers/sandboxes/process_output.py +++ b/hyperbrowser/client/managers/sandboxes/process_output.py @@ -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: @@ -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) diff --git a/tests/test_sandbox_process_collection.py b/tests/test_sandbox_process_collection.py index 1171bf04..096d3c87 100644 --- a/tests/test_sandbox_process_collection.py +++ b/tests/test_sandbox_process_collection.py @@ -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)