Skip to content

Commit 1a0efd9

Browse files
committed
Draft decorator to enhance not existing storage error message in local runs without force_cloud
1 parent e61bb0f commit 1a0efd9

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/apify/_actor.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import asyncio
4+
import functools
45
import os
56
import sys
67
from datetime import timedelta
@@ -49,6 +50,24 @@
4950

5051

5152
MainReturnType = TypeVar('MainReturnType')
53+
TFun = TypeVar('TFun', bound=Callable[..., Any])
54+
55+
56+
def _add_local_storage_error_hint(function: TFun) -> TFun:
57+
"""This decorator adds a local storage error hint in situation where storage was not found locally."""
58+
59+
@functools.wraps(function)
60+
async def wrapper(
61+
self: _ActorType, *, id: str | None = None, name: str | None = None, force_cloud: bool = False
62+
) -> Any:
63+
try:
64+
return await function(self=self, id=id, name=name, force_cloud=force_cloud)
65+
except Exception as e:
66+
if not force_cloud:
67+
e.args = (f'{e.args[0]} (If you are trying to retrieve a remote storage, use `force_cloud=True`.)',)
68+
raise
69+
70+
return cast(TFun, wrapper)
5271

5372

5473
@docs_name('Actor')
@@ -353,6 +372,7 @@ def new_client(
353372
timeout_secs=int(timeout.total_seconds()) if timeout else None,
354373
)
355374

375+
@_add_local_storage_error_hint
356376
async def open_dataset(
357377
self,
358378
*,
@@ -389,6 +409,7 @@ async def open_dataset(
389409
storage_client=storage_client,
390410
)
391411

412+
@_add_local_storage_error_hint
392413
async def open_key_value_store(
393414
self,
394415
*,
@@ -423,6 +444,7 @@ async def open_key_value_store(
423444
storage_client=storage_client,
424445
)
425446

447+
@_add_local_storage_error_hint
426448
async def open_request_queue(
427449
self,
428450
*,

0 commit comments

Comments
 (0)