Skip to content

Commit a2cc987

Browse files
authored
fix: Only log any error that happens during log redirection (#866)
# Description - Never raise an error on a log redirection problem. (This was hidden by [a bug in impit, which is going to be fixed soon](apify/impit#482) and it would lead to similar issue observed in JS client apify/apify-client-js#873) - Use `~` on `impit` and pin to the latest version `0.12.0` . Zero versioned releases can have breaking changes even in minor versions. Bumping impit version to new minor version should be an intentional action. (Expected release of impit `0.13.0` would break client without this change) # Issues Closes: #864
1 parent 3e21ff0 commit a2cc987

3 files changed

Lines changed: 15 additions & 11 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ classifiers = [
2525
keywords = ["apify", "api", "client", "automation", "crawling", "scraping"]
2626
dependencies = [
2727
"colorama>=0.4.0",
28-
"impit>=0.9.2",
28+
"impit~=0.12.0",
2929
"more_itertools>=10.0.0",
3030
"pydantic[email]>=2.11.0",
3131
]

src/apify_client/_streamed_log.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -215,12 +215,16 @@ async def __aexit__(
215215
await self.stop()
216216

217217
async def _stream_log(self) -> None:
218-
async with self._log_client.stream(raw=True) as log_stream:
219-
if not log_stream:
220-
return
221-
try:
222-
async for data in log_stream.aiter_bytes():
223-
self._process_new_data(data)
224-
finally:
225-
# Flush the last buffered part even if the task is cancelled by `stop()`.
226-
self._log_buffer_content(include_last_part=True)
218+
try:
219+
async with self._log_client.stream(raw=True) as log_stream:
220+
if not log_stream:
221+
return
222+
try:
223+
async for data in log_stream.aiter_bytes():
224+
self._process_new_data(data)
225+
finally:
226+
# Flush the last buffered part even if the task is cancelled by `stop()`.
227+
self._log_buffer_content(include_last_part=True)
228+
except Exception:
229+
# Exception in log redirection should not propagate further.
230+
self._to_logger.exception('Log redirection stopped due to unexpected error:')

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)