|
1 | 1 | from __future__ import annotations
|
2 | 2 |
|
3 | 3 | import asyncio
|
| 4 | +import functools |
4 | 5 | import os
|
5 | 6 | import sys
|
6 | 7 | from datetime import timedelta
|
|
49 | 50 |
|
50 | 51 |
|
51 | 52 | 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) |
52 | 71 |
|
53 | 72 |
|
54 | 73 | @docs_name('Actor')
|
@@ -353,6 +372,7 @@ def new_client(
|
353 | 372 | timeout_secs=int(timeout.total_seconds()) if timeout else None,
|
354 | 373 | )
|
355 | 374 |
|
| 375 | + @_add_local_storage_error_hint |
356 | 376 | async def open_dataset(
|
357 | 377 | self,
|
358 | 378 | *,
|
@@ -389,6 +409,7 @@ async def open_dataset(
|
389 | 409 | storage_client=storage_client,
|
390 | 410 | )
|
391 | 411 |
|
| 412 | + @_add_local_storage_error_hint |
392 | 413 | async def open_key_value_store(
|
393 | 414 | self,
|
394 | 415 | *,
|
@@ -423,6 +444,7 @@ async def open_key_value_store(
|
423 | 444 | storage_client=storage_client,
|
424 | 445 | )
|
425 | 446 |
|
| 447 | + @_add_local_storage_error_hint |
426 | 448 | async def open_request_queue(
|
427 | 449 | self,
|
428 | 450 | *,
|
|
0 commit comments