feat: add type property to TimeoutException/TimeoutError (#463)#1187
feat: add type property to TimeoutException/TimeoutError (#463)#1187MaxwellCalkin wants to merge 2 commits intoe2b-dev:mainfrom
Conversation
…atic timeout identification Fixes e2b-dev#463. Previously, users had to parse the error message string to determine what kind of timeout occurred (sandbox vs request vs execution). Now both the Python and JS SDKs expose a `type` property (TimeoutType enum) on timeout exceptions, enabling clean programmatic handling. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1450cbb14b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| """ | ||
|
|
||
| pass | ||
| def __init__(self, message: str, type: TimeoutType = TimeoutType.SANDBOX): |
There was a problem hiding this comment.
Preserve no-arg construction for TimeoutException
This new __init__ requires a message, which is a behavioral break from the previous Exception-inherited constructor that allowed TimeoutException() / raise TimeoutException with no arguments. Downstream code that synthesizes this exception in tests, mocks, or wrappers will now raise TypeError before it can be handled, so the change is not fully backward compatible as described.
Useful? React with 👍 / 👎.
Preserve backward compatibility by defaulting message to "Timeout" so that TimeoutException() with no arguments still works. This prevents TypeError in downstream code that constructs the exception without a message. Addresses review feedback from Codex bot. AI Disclosure: This commit was authored by Claude Opus 4.6 (Anthropic), an AI agent operated by Maxwell Calkin (@MaxwellCalkin).
Summary
Fixes #463.
TimeoutException(Python) andTimeoutError(JS) are raised for three distinct timeout scenarios, but users have no way to distinguish them programmatically — they must parse the error message string, which is fragile and error-prone.This PR adds a
TimeoutTypeenum and atypeproperty to both SDKs:TimeoutTypeSANDBOXtimeout/.set_timeout()timeoutMs/.setTimeout()REQUESTrequest_timeoutrequestTimeoutMsEXECUTIONtimeoutoncommands.run()etc.timeoutMsoncommands.run()etc.Python SDK
JS/TS SDK
Changes
packages/python-sdk/e2b/exceptions.py): AddedTimeoutType(str, Enum)withSANDBOX,REQUEST,EXECUTIONvalues. UpdatedTimeoutException.__init__to accept atypeparameter (defaults toSANDBOX). Updated all factory functions (format_sandbox_timeout_exception,format_request_timeout_error,format_execution_timeout_error) to pass the appropriate type.packages/python-sdk/e2b/envd/rpc.py): Updatedhandle_rpc_exceptionto passTimeoutType.REQUESTforCode.canceledandTimeoutType.EXECUTIONforCode.deadline_exceeded.packages/python-sdk/e2b/__init__.py): ExportedTimeoutType.packages/js-sdk/src/errors.ts): AddedTimeoutTypeenum. UpdatedTimeoutErrorconstructor to accept atypeparameter (defaults toSANDBOX). UpdatedformatSandboxTimeoutError.packages/js-sdk/src/envd/rpc.ts): UpdatedhandleRpcErrorto passTimeoutType.REQUESTforCode.CanceledandTimeoutType.EXECUTIONforCode.DeadlineExceeded.packages/js-sdk/src/index.ts): ExportedTimeoutType.Backward compatibility
Fully backward compatible — the
typeparameter defaults toTimeoutType.SANDBOXin both SDKs, so existingexcept TimeoutException/catch (e)blocks continue to work without changes.