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
5 changes: 5 additions & 0 deletions .changeset/fix-command-handle-sandbox-exception.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"e2b": patch
---

Raise `SandboxException` instead of bare `Exception` in `CommandHandle.wait()` when the command stream ends without an exit event, giving a clearer error message when the sandbox was killed, paused, or timed out mid-stream.
4 changes: 3 additions & 1 deletion packages/js-sdk/src/sandbox/commands/commandHandle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ export class CommandHandle
* If the command exits with a non-zero exit code, it throws a `CommandExitError`.
*
* @returns `CommandResult` result of command execution.
* @throws {CommandExitError} the command exited with a non-zero exit code
* @throws {SandboxError} the command stream ended before an exit event was received, e.g. the sandbox was killed or timed out
*/
async wait() {
await this._wait
Expand All @@ -171,7 +173,7 @@ export class CommandHandle
}

if (!this.result) {
throw new SandboxError('Process exited without a result')
throw new SandboxError('Command stream ended without an exit event. The sandbox is no longer running — it may have been killed, paused, or timed out.')
}

if (this.result.exitCode !== 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,13 +244,17 @@ async def wait(self) -> CommandResult:
If the command exits with a non-zero exit code, it throws a `CommandExitException`.

:return: `CommandResult` result of command execution
:raises CommandExitException: the command exited with a non-zero exit code
:raises SandboxException: the command stream ended before an exit event was received, e.g. the sandbox was killed or timed out
"""
await self._wait
if self._iteration_exception:
raise self._iteration_exception

if self._result is None:
raise Exception("Command ended without an end event")
raise SandboxException(
"Command stream ended without an exit event. The sandbox may have been killed, paused, or timed out."
)
Comment thread
AdaAibaby marked this conversation as resolved.
Comment thread
AdaAibaby marked this conversation as resolved.

if self._result.exit_code != 0:
raise CommandExitException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ def wait(
:param on_stderr: Callback for stderr output

:return: `CommandResult` result of command execution
:raises CommandExitException: the command exited with a non-zero exit code
:raises SandboxException: the command stream ended before an exit event was received, e.g. the sandbox was killed or timed out
"""
try:
for stdout, stderr, pty in self:
Expand All @@ -193,7 +195,9 @@ def wait(
raise self._iteration_exception

if self._result is None:
raise Exception("Command ended without an end event")
raise SandboxException(
"Command stream ended without an exit event. The sandbox may have been killed, paused, or timed out."
)
Comment thread
AdaAibaby marked this conversation as resolved.

if self._result.exit_code != 0:
raise CommandExitException(
Expand Down