Skip to content

Commit 359cf57

Browse files
authored
Preserve coroutine errors without a response local (#1041)
1 parent 6d5b34b commit 359cf57

3 files changed

Lines changed: 36 additions & 4 deletions

File tree

‎docs/source/changelog.rst‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
Changelog
22
=========
33

4+
Dev
5+
---
6+
7+
- Preserve the original coroutine-related error when its traceback has no response (#1011)
8+
49
2026.7.0
510
--------
611

‎s3fs/core.py‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,11 @@ async def _error_wrapper(func, *, args=(), kwargs=None, retries):
207207
tb = err.__traceback__
208208
while tb.tb_next:
209209
tb = tb.tb_next
210-
try:
211-
await tb.tb_frame.f_locals["response"]
212-
except Exception as e:
213-
err = e
210+
if "response" in tb.tb_frame.f_locals:
211+
try:
212+
await tb.tb_frame.f_locals["response"]
213+
except Exception as e:
214+
err = e
214215
err = translate_boto_error(err)
215216
raise err
216217

‎s3fs/tests/test_custom_error_handler.py‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,32 @@ class CustomNonRetryableError(Exception):
2626
pass
2727

2828

29+
def test_coroutine_error_without_response_preserves_original():
30+
error = TypeError("'coroutine' object is not subscriptable")
31+
32+
async def failing_func():
33+
raise error
34+
35+
with pytest.raises(TypeError) as exc:
36+
asyncio.run(_error_wrapper(failing_func, retries=1))
37+
assert exc.value is error
38+
39+
40+
def test_coroutine_error_recovers_response_exception():
41+
async def response_error():
42+
raise ClientError(
43+
{"Error": {"Code": "AccessDenied", "Message": "Access denied"}},
44+
"PutObject",
45+
)
46+
47+
async def failing_func():
48+
response = response_error()
49+
return response["Body"]
50+
51+
with pytest.raises(PermissionError, match="Access denied"):
52+
asyncio.run(_error_wrapper(failing_func, retries=1))
53+
54+
2955
@pytest.fixture(autouse=True)
3056
def reset_error_handler():
3157
"""Reset the custom error handler and retryable errors after each test."""

0 commit comments

Comments
 (0)