-
Notifications
You must be signed in to change notification settings - Fork 17k
fix(task-sdk): include error details in ServerResponseError string representation #63368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -175,6 +175,45 @@ def test_server_response_error_pickling(self): | |||||||||||||||||||||||||||||||||
| assert unpickled.response.status_code == 404 | ||||||||||||||||||||||||||||||||||
| assert unpickled.request.url == "http://error" | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| def test_server_response_error_str_includes_detail(self): | ||||||||||||||||||||||||||||||||||
| """Test that ServerResponseError string representation includes error details.""" | ||||||||||||||||||||||||||||||||||
| responses = [ | ||||||||||||||||||||||||||||||||||
| httpx.Response( | ||||||||||||||||||||||||||||||||||
| 409, | ||||||||||||||||||||||||||||||||||
| json={"detail": {"reason": "invalid_state", "message": "TI was not in the running state"}}, | ||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||
| client = make_client_w_responses(responses) | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| with pytest.raises(ServerResponseError) as exc_info: | ||||||||||||||||||||||||||||||||||
| client.get("http://error") | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| err = exc_info.value | ||||||||||||||||||||||||||||||||||
| error_str = str(err) | ||||||||||||||||||||||||||||||||||
| assert "Detail:" in error_str | ||||||||||||||||||||||||||||||||||
| assert "invalid_state" in error_str | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| def test_server_response_error_str_without_detail(self): | ||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test appears to covering scenarios where detail exists but is
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added |
||||||||||||||||||||||||||||||||||
| """Test that ServerResponseError string without detail doesn't include Detail section.""" | ||||||||||||||||||||||||||||||||||
| # 422 with a string detail: the string becomes the message, detail attr is None | ||||||||||||||||||||||||||||||||||
| responses = [httpx.Response(422, json={"detail": "Simple error"})] | ||||||||||||||||||||||||||||||||||
| client = make_client_w_responses(responses) | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| with pytest.raises(ServerResponseError) as exc_info: | ||||||||||||||||||||||||||||||||||
| client.get("http://error") | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| err = exc_info.value | ||||||||||||||||||||||||||||||||||
| error_str = str(err) | ||||||||||||||||||||||||||||||||||
| assert "Simple error" in error_str | ||||||||||||||||||||||||||||||||||
| # detail is None when the detail string is used as the message itself | ||||||||||||||||||||||||||||||||||
| assert "Detail:" not in error_str | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| def test_server_response_error_str_missing_detail_attr(self): | ||||||||||||||||||||||||||||||||||
| err = ServerResponseError.__new__(ServerResponseError) | ||||||||||||||||||||||||||||||||||
| err.args = ("Server returned error",) | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
|
Comment on lines
+212
to
+214
|
||||||||||||||||||||||||||||||||||
| err = ServerResponseError.__new__(ServerResponseError) | |
| err.args = ("Server returned error",) | |
| responses = [ | |
| httpx.Response( | |
| 409, | |
| json={"detail": {"reason": "invalid_state", "message": "TI was not in the running state"}}, | |
| ) | |
| ] | |
| client = make_client_w_responses(responses) | |
| with pytest.raises(ServerResponseError) as exc_info: | |
| client.get("http://error") | |
| err = exc_info.value | |
| if "detail" in err.__dict__: | |
| del err.__dict__["detail"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
if detail := ...check is truthiness-based, so empty-but-present details (e.g.,{}/[]) will be omitted even thoughdetailexists. If the intent is to include details whenever the attribute is present (and notNone), assign first and checkdetail is not None(or alternatively checkhasattr(self, 'detail')andself.detail is not None).