fix: raise Python exception on response body read error#313
Merged
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR fixes the Python bindings to properly raise exceptions when response body read errors occur, instead of silently returning empty bodies. The key change is making the ImpitPyResponse::from_async method return a Result and propagating errors from the bytes() call.
Key Changes
- Modified error handling infrastructure to support optional context information when errors occur without full request context
- Changed
ImpitPyResponse::from_asyncto returnResult<Self, ImpitError>and propagate body read errors - Updated both sync and async client implementations to properly handle and convert the new error type
Reviewed Changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| impit/src/errors.rs | Made ErrorContext fields optional and updated ImpitError::from to accept Option to support error creation without full context |
| impit/src/impit.rs | Updated ErrorContext construction to wrap fields in Some() to match the new optional field structure |
| impit-python/src/response.rs | Changed from_async to return Result and propagate errors from bytes() call instead of defaulting to empty body |
| impit-python/src/client.rs | Updated error handling to properly convert ImpitError from from_async into ImpitPyError |
| impit-python/src/async_client.rs | Updated error handling to properly convert ImpitError from from_async into PyErr |
| impit-python/Cargo.toml | Added "auto-initialize" feature to pyo3 dependency |
| impit-python/uv.lock | Bumped version from 0.8.0 to 0.9.0 |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Originally, Python Impit bindings would return a response with an empty body on a body read error. This didn't make much sense and caused issues in the downstream dependencies. Now we rethrow the error so it can be properly handled.
Closes apify/apify-sdk-python#672