Uh oh!
There was an error while loading. Please reload this page.
fix: standardize sandbox data api errors - #95
Conversation
TJKkking
commented
Apr 30, 2026
@claude code review |
Raise ClientError/ServerError for Sandbox HTTP JSON error responses and expose structured error metadata on HTTPError. Document the breaking migration in release notes. Tests: uv run pytest tests/unittests/utils/test_exception.py tests/unittests/sandbox/api/test_sandbox_data.py; uv run pytest tests/unittests/sandbox/api/test_code_interpreter_data.py tests/unittests/sandbox/api/test_browser_data.py tests/unittests/sandbox/api/test_aio_data.py tests/unittests/sandbox/test_client.py. Type check: targeted mypy passed for modified files. Full mypy is blocked by existing duplicate module sandbox from local/sandbox/__init__.py and examples/sandbox.py. Signed-off-by: 寒光 <2510399607@qq.com>
…le isolation - Added an `autouse` fixture to automatically clean up environment variables related to the SDK configuration. - Prevents local `.env` files from interfering with the environment variable settings used in unit tests. - Cleans up specific environment variables to prevent assertion failures within `respx` mocks. - Ensures environment variable isolation between test cases, thereby enhancing test stability. - Cleans up only those environment variables that the SDK reads by default, without affecting user-defined variables. Signed-off-by: 寒光 <2510399607@qq.com>
There was a problem hiding this comment.
Pull request overview
Standardizes Sandbox data-plane HTTP JSON API error handling so callers receive consistent ClientError/ServerError exceptions (with structured metadata) instead of needing to inspect returned dictionaries.
Changes:
- Extend
HTTPErrorto carryerror_code,response_body, andresponse_headers, and update string formatting to avoid expanding response metadata. - Update
SandboxDataAPIHTTP handling to raiseClientErrorfor4xxandServerErrorfor5xxJSON error responses (sync + async), with robust request-id extraction. - Add unit tests for the new exception fields/formatting and Sandbox data-plane HTTP behaviors; add release notes documenting the breaking migration.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/unittests/utils/test_exception.py | Adds coverage for new HTTPError metadata fields and updated __str__ behavior. |
| tests/unittests/sandbox/api/test_sandbox_data.py | Adds respx-based tests validating sandbox data-plane success/error behaviors for sync/async calls. |
| tests/unittests/conftest.py | Adds autouse env isolation to prevent local .env from polluting unit tests. |
| agentrun/utils/exception.py | Adds structured error metadata to HTTPError and updates formatting; simplifies ClientError/ServerError. |
| agentrun/sandbox/api/sandbox_data.py | Implements standardized HTTP JSON error raising and structured error extraction for Sandbox data-plane requests. |
| agentrun/sandbox/api/__sandbox_data_async_template.py | Updates codegen template to match the new sandbox data-plane HTTP error handling behavior. |
| RELEASE_NOTES.md | Documents the breaking behavior change and migration guidance. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
OhYee
commented
Apr 30, 2026
@copilot 检查下是否存在隐患,是否存在不兼容变动 |
以下是变更中存在的隐患及不兼容点分析: 已记录的 Breaking Change(在 RELEASE_NOTES.md 中有说明)
未记录的 Breaking Change
潜在风险(功能不一致)
向后兼容改动(无风险)
建议:在 RELEASE_NOTES.md 中补充 |
…mat change Agent-Logs-Url: https://github.com/Serverless-Devs/agentrun-sdk-python/sessions/521d41f7-af5d-44a2-9ba2-b04863849851 Co-authored-by: OhYee <13498329+OhYee@users.noreply.github.com>
Uh oh!
There was an error while loading. Please reload this page.
Raise ClientError/ServerError for Sandbox HTTP JSON error responses and expose structured error metadata on HTTPError. Document the breaking migration in release notes.
Tests: uv run pytest tests/unittests/utils/test_exception.py tests/unittests/sandbox/api/test_sandbox_data.py; uv run pytest tests/unittests/sandbox/api/test_code_interpreter_data.py tests/unittests/sandbox/api/test_browser_data.py tests/unittests/sandbox/api/test_aio_data.py tests/unittests/sandbox/test_client.py.
Type check: targeted mypy passed for modified files. Full mypy is blocked by existing duplicate module sandbox from local/sandbox/init.py and examples/sandbox.py.
Fix bugs
Bug detail
Pull request tasks
Update docs
Reason for update
Pull request tasks
Add contributor
Contributed content
Content detail
Others
Reason for update