Skip to content

Commit 1df4431

Browse files
mishushakovclaude
andcommitted
Rename error handlers to match main SDK conventions
Align with e2b-dev/E2B#1419, which names the health-check-aware error wrappers handle*Error / handle_*_exception: - JS: formatRequestError -> handleRequestError - Python: _raise_if_sandbox_killed -> _handle_connection_error Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent d40a189 commit 1df4431

3 files changed

Lines changed: 18 additions & 18 deletions

File tree

js/src/sandbox.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ export class Sandbox extends BaseSandbox {
279279

280280
return execution
281281
} catch (error) {
282-
throw await this.formatRequestError(error)
282+
throw await this.handleRequestError(error)
283283
}
284284
}
285285

@@ -318,7 +318,7 @@ export class Sandbox extends BaseSandbox {
318318

319319
return await res.json()
320320
} catch (error) {
321-
throw await this.formatRequestError(error)
321+
throw await this.handleRequestError(error)
322322
}
323323
}
324324

@@ -354,7 +354,7 @@ export class Sandbox extends BaseSandbox {
354354
throw error
355355
}
356356
} catch (error) {
357-
throw await this.formatRequestError(error)
357+
throw await this.handleRequestError(error)
358358
}
359359
}
360360

@@ -389,7 +389,7 @@ export class Sandbox extends BaseSandbox {
389389

390390
return await res.json()
391391
} catch (error) {
392-
throw await this.formatRequestError(error)
392+
throw await this.handleRequestError(error)
393393
}
394394
}
395395

@@ -425,7 +425,7 @@ export class Sandbox extends BaseSandbox {
425425
throw error
426426
}
427427
} catch (error) {
428-
throw await this.formatRequestError(error)
428+
throw await this.handleRequestError(error)
429429
}
430430
}
431431

@@ -435,7 +435,7 @@ export class Sandbox extends BaseSandbox {
435435
* `TimeoutError`. Otherwise falls back to formatting request timeouts and
436436
* re-throwing the original error.
437437
*/
438-
private async formatRequestError(error: unknown): Promise<unknown> {
438+
private async handleRequestError(error: unknown): Promise<unknown> {
439439
if (
440440
isConnectionClosedError(error) &&
441441
// If the state check itself fails we can't tell whether the sandbox

python/e2b_code_interpreter/code_interpreter_async.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def _client(self) -> AsyncClient:
8484
transport=get_transport(self.connection_config, http2=False),
8585
)
8686

87-
async def _raise_if_sandbox_killed(self, err: Exception) -> None:
87+
async def _handle_connection_error(self, err: Exception) -> None:
8888
"""
8989
Raises a descriptive exception if the connection error was caused by
9090
the sandbox being killed mid-request. If the sandbox is still running
@@ -236,7 +236,7 @@ async def run_code(
236236
except httpx.TimeoutException:
237237
raise format_request_timeout_error()
238238
except (httpx.ReadError, httpx.RemoteProtocolError) as err:
239-
await self._raise_if_sandbox_killed(err)
239+
await self._handle_connection_error(err)
240240
raise
241241

242242
async def create_code_context(
@@ -285,7 +285,7 @@ async def create_code_context(
285285
except httpx.TimeoutException:
286286
raise format_request_timeout_error()
287287
except (httpx.ReadError, httpx.RemoteProtocolError) as err:
288-
await self._raise_if_sandbox_killed(err)
288+
await self._handle_connection_error(err)
289289
raise
290290

291291
async def remove_code_context(
@@ -320,7 +320,7 @@ async def remove_code_context(
320320
except httpx.TimeoutException:
321321
raise format_request_timeout_error()
322322
except (httpx.ReadError, httpx.RemoteProtocolError) as err:
323-
await self._raise_if_sandbox_killed(err)
323+
await self._handle_connection_error(err)
324324
raise
325325

326326
async def list_code_contexts(self) -> List[Context]:
@@ -351,7 +351,7 @@ async def list_code_contexts(self) -> List[Context]:
351351
except httpx.TimeoutException:
352352
raise format_request_timeout_error()
353353
except (httpx.ReadError, httpx.RemoteProtocolError) as err:
354-
await self._raise_if_sandbox_killed(err)
354+
await self._handle_connection_error(err)
355355
raise
356356

357357
async def restart_code_context(
@@ -385,5 +385,5 @@ async def restart_code_context(
385385
except httpx.TimeoutException:
386386
raise format_request_timeout_error()
387387
except (httpx.ReadError, httpx.RemoteProtocolError) as err:
388-
await self._raise_if_sandbox_killed(err)
388+
await self._handle_connection_error(err)
389389
raise

python/e2b_code_interpreter/code_interpreter_sync.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def _client(self) -> Client:
7878
# cancelled reliably.
7979
return Client(transport=get_transport(self.connection_config, http2=False))
8080

81-
def _raise_if_sandbox_killed(self, err: Exception) -> None:
81+
def _handle_connection_error(self, err: Exception) -> None:
8282
"""
8383
Raises a descriptive exception if the connection error was caused by
8484
the sandbox being killed mid-request. If the sandbox is still running
@@ -229,7 +229,7 @@ def run_code(
229229
except httpx.TimeoutException:
230230
raise format_request_timeout_error()
231231
except (httpx.ReadError, httpx.RemoteProtocolError) as err:
232-
self._raise_if_sandbox_killed(err)
232+
self._handle_connection_error(err)
233233
raise
234234

235235
def create_code_context(
@@ -278,7 +278,7 @@ def create_code_context(
278278
except httpx.TimeoutException:
279279
raise format_request_timeout_error()
280280
except (httpx.ReadError, httpx.RemoteProtocolError) as err:
281-
self._raise_if_sandbox_killed(err)
281+
self._handle_connection_error(err)
282282
raise
283283

284284
def remove_code_context(
@@ -313,7 +313,7 @@ def remove_code_context(
313313
except httpx.TimeoutException:
314314
raise format_request_timeout_error()
315315
except (httpx.ReadError, httpx.RemoteProtocolError) as err:
316-
self._raise_if_sandbox_killed(err)
316+
self._handle_connection_error(err)
317317
raise
318318

319319
def list_code_contexts(self) -> List[Context]:
@@ -344,7 +344,7 @@ def list_code_contexts(self) -> List[Context]:
344344
except httpx.TimeoutException:
345345
raise format_request_timeout_error()
346346
except (httpx.ReadError, httpx.RemoteProtocolError) as err:
347-
self._raise_if_sandbox_killed(err)
347+
self._handle_connection_error(err)
348348
raise
349349

350350
def restart_code_context(
@@ -379,5 +379,5 @@ def restart_code_context(
379379
except httpx.TimeoutException:
380380
raise format_request_timeout_error()
381381
except (httpx.ReadError, httpx.RemoteProtocolError) as err:
382-
self._raise_if_sandbox_killed(err)
382+
self._handle_connection_error(err)
383383
raise

0 commit comments

Comments
 (0)