Skip to content

Commit 50744ae

Browse files
authored
Merge pull request #113 from praw-dev/timeout-exception-handling
Add more logging details for asyncio.TimeoutException
2 parents 90a47f3 + 1c3dc16 commit 50744ae

File tree

6 files changed

+32
-8
lines changed

6 files changed

+32
-8
lines changed

.github/dependabot.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,4 @@ updates:
77
- package-ecosystem: uv
88
directory: /
99
schedule:
10-
interval: cron
11-
cronjob: "46 17 * * *"
10+
interval: weekly

CHANGES.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ asyncprawcore follows `semantic versioning <https://semver.org/>`_.
66
Unreleased
77
----------
88

9+
**Changed**
10+
11+
- Improved exception message when ``asyncio.TimeoutError`` is raised.
12+
913
3.0.2 (2025/08/06)
1014
------------------
1115

asyncprawcore/auth.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ async def revoke_token(self, token: str, token_type: str | None = None) -> None:
124124
if token_type is not None:
125125
data["token_type_hint"] = token_type
126126
url = self._requestor.reddit_url + const.REVOKE_TOKEN_PATH
127-
async with self._post(url=url, **data) as _:
128-
pass # The response is not used.
127+
async with self._post(url=url, **data):
128+
pass
129129

130130

131131
class BaseAuthorizer:

asyncprawcore/exceptions.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from __future__ import annotations
44

5+
import asyncio
56
from typing import TYPE_CHECKING, Any
67
from urllib.parse import urlparse
78

@@ -56,7 +57,9 @@ def __init__(
5657
self.original_exception = original_exception
5758
self.request_args = request_args
5859
self.request_kwargs = request_kwargs
59-
super().__init__(f"error with request {original_exception}")
60+
super().__init__(
61+
f"error with request {'TimeoutError' if isinstance(original_exception, asyncio.TimeoutError) else original_exception}"
62+
)
6063

6164

6265
class ResponseException(AsyncPrawcoreException):

pyproject.toml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[build-system]
2-
build-backend = "flit_core.buildapi"
3-
requires = ["flit_core >=3.4,<4"]
2+
build-backend = "hatchling.build"
3+
requires = ["hatchling"]
44

55
[dependency-groups]
66
dev = [
@@ -61,15 +61,18 @@ requires-python = ">=3.9"
6161
"Issue Tracker" = "https://github.com/praw-dev/asyncprawcore/issues"
6262
"Source Code" = "https://github.com/praw-dev/asyncprawcore"
6363

64+
[tool.hatch.version]
65+
path = "asyncprawcore/__init__.py"
66+
6467
[tool.pytest.ini_options]
6568
asyncio_mode = "auto"
6669
filterwarnings = "ignore::DeprecationWarning"
6770
testpaths = "tests"
6871

6972
[tool.ruff]
7073
include = [
71-
"examples/*.py",
7274
"asyncprawcore/*.py",
75+
"examples/*.py",
7376
"tests/*.py"
7477
]
7578
line-length = 120

tests/unit/test_requestor.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,18 @@ async def test_request__wrap_request_exceptions(self, mock_session):
6868
assert exception is exception_info.value.original_exception
6969
assert exception_info.value.request_args == ("get", "http://a.b")
7070
assert exception_info.value.request_kwargs == {"data": "bar"}
71+
72+
@patch("aiohttp.ClientSession")
73+
async def test_request__wrap_request_exceptions__timeout(self, mock_session):
74+
exception = asyncio.TimeoutError()
75+
session_instance = mock_session.return_value
76+
session_instance.request.side_effect = exception
77+
requestor = asyncprawcore.Requestor("asyncprawcore:test (by u/Lil_SpazJoekp)")
78+
with pytest.raises(asyncprawcore.RequestException) as exception_info:
79+
async with requestor.request("get", "http://a.b", data="bar") as _:
80+
pass # pragma: no cover
81+
assert isinstance(exception_info.value, RequestException)
82+
assert exception is exception_info.value.original_exception
83+
assert str(exception_info.value) == "error with request TimeoutError"
84+
assert exception_info.value.request_args == ("get", "http://a.b")
85+
assert exception_info.value.request_kwargs == {"data": "bar"}

0 commit comments

Comments
 (0)