Skip to content

Commit

Permalink
Handle exception when iterating over process output
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubno committed Jan 24, 2025
1 parent 5b3f58b commit fd45f0e
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions packages/python-sdk/e2b/sandbox_sync/commands/command_handle.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,25 +62,28 @@ def _handle_events(
None,
None,
]:
for event in self._events:
if event.event.HasField("data"):
if event.event.data.stdout:
out = event.event.data.stdout.decode('utf-8', 'replace')
self._stdout += out
yield out, None, None
if event.event.data.stderr:
out = event.event.data.stderr.decode('utf-8', 'replace')
self._stderr += out
yield None, out, None
if event.event.data.pty:
yield None, None, event.event.data.pty
if event.event.HasField("end"):
self._result = CommandResult(
stdout=self._stdout,
stderr=self._stderr,
exit_code=event.event.end.exit_code,
error=event.event.end.error,
)
try:
for event in self._events:
if event.event.HasField("data"):
if event.event.data.stdout:
out = event.event.data.stdout.decode("utf-8", "replace")
self._stdout += out
yield out, None, None
if event.event.data.stderr:
out = event.event.data.stderr.decode("utf-8", "replace")
self._stderr += out
yield None, out, None
if event.event.data.pty:
yield None, None, event.event.data.pty
if event.event.HasField("end"):
self._result = CommandResult(
stdout=self._stdout,
stderr=self._stderr,
exit_code=event.event.end.exit_code,
error=event.event.end.error,
)
except Exception as e:
raise handle_rpc_exception(e)

def disconnect(self) -> None:
"""
Expand Down

0 comments on commit fd45f0e

Please sign in to comment.