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
6 changes: 6 additions & 0 deletions .changeset/ten-books-clean.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@e2b/python-sdk': patch
'e2b': patch
---

Improve SDK returned errors
8 changes: 8 additions & 0 deletions packages/js-sdk/src/sandbox/sandboxApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,10 @@ export class SandboxApi {
signal: config.getSignal(opts?.requestTimeoutMs),
})

if (res.error?.code === 404) {
throw new NotFoundError(`Sandbox ${sandboxId} not found`)
}

const err = handleApiError(res)
if (err) {
throw err
Expand All @@ -376,6 +380,10 @@ export class SandboxApi {
signal: config.getSignal(opts?.requestTimeoutMs),
})

if (res.error?.code === 404) {
throw new NotFoundError(`Sandbox ${sandboxId} not found`)
}

const err = handleApiError(res)
if (err) {
throw err
Expand Down
6 changes: 6 additions & 0 deletions packages/python-sdk/e2b/sandbox_async/sandbox_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ async def _cls_get_info(
client=api_client,
)

if res.status_code == 404:
raise NotFoundException(f"Sandbox {sandbox_id} not found")

if res.status_code >= 300:
raise handle_api_exception(res)

Expand Down Expand Up @@ -139,6 +142,9 @@ async def _cls_set_timeout(
body=PostSandboxesSandboxIDTimeoutBody(timeout=timeout),
)

if res.status_code == 404:
raise NotFoundException(f"Paused sandbox {sandbox_id} not found")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Incorrect Error Message for Sandbox Timeout

The async _cls_set_timeout method's 404 error message incorrectly specifies "Paused sandbox {sandbox_id} not found". The set_timeout operation applies to any sandbox state, not just paused ones, making this message misleading and inconsistent with the sync version.

Additional Locations (1)

Fix in Cursor Fix in Web


if res.status_code >= 300:
raise handle_api_exception(res)

Expand Down
6 changes: 6 additions & 0 deletions packages/python-sdk/e2b/sandbox_sync/sandbox_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ def _cls_get_info(
client=api_client,
)

if res.status_code == 404:
raise NotFoundException(f"Sandbox {sandbox_id} not found")

if res.status_code >= 300:
raise handle_api_exception(res)

Expand Down Expand Up @@ -138,6 +141,9 @@ def _cls_set_timeout(
body=PostSandboxesSandboxIDTimeoutBody(timeout=timeout),
)

if res.status_code == 404:
raise NotFoundException(f"Sandbox {sandbox_id} not found")

if res.status_code >= 300:
raise handle_api_exception(res)

Expand Down