-
Notifications
You must be signed in to change notification settings - Fork 15
chore: Enhanced missing local storage error #427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
from __future__ import annotations | ||
|
||
import asyncio | ||
import functools | ||
import os | ||
import sys | ||
from contextlib import suppress | ||
|
@@ -50,6 +51,26 @@ | |
|
||
|
||
MainReturnType = TypeVar('MainReturnType') | ||
TFun = TypeVar('TFun', bound=Callable[..., Any]) | ||
|
||
|
||
def _add_local_storage_error_hint(function: TFun) -> TFun: | ||
"""This decorator adds a local storage error hint in situation where storage was not found locally.""" | ||
|
||
@functools.wraps(function) | ||
async def wrapper( | ||
self: _ActorType, *, id: str | None = None, name: str | None = None, force_cloud: bool = False | ||
) -> Any: | ||
try: | ||
return await function(self=self, id=id, name=name, force_cloud=force_cloud) | ||
except Exception as e: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we really want to catch all exceptions? |
||
if not force_cloud: | ||
e.args = ( | ||
f'{e.args[0]} (If you are trying to retrieve a remote storage, use `force_cloud=True` argument.)', | ||
) | ||
Comment on lines
+68
to
+70
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Couldn't |
||
raise | ||
|
||
return cast(TFun, wrapper) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we really need the cast? Doesn't |
||
|
||
|
||
@docs_name('Actor') | ||
|
@@ -362,6 +383,7 @@ def new_client( | |
timeout_secs=int(timeout.total_seconds()) if timeout else None, | ||
) | ||
|
||
@_add_local_storage_error_hint | ||
async def open_dataset( | ||
self, | ||
*, | ||
|
@@ -398,6 +420,7 @@ async def open_dataset( | |
storage_client=storage_client, | ||
) | ||
|
||
@_add_local_storage_error_hint | ||
async def open_key_value_store( | ||
self, | ||
*, | ||
|
@@ -432,6 +455,7 @@ async def open_key_value_store( | |
storage_client=storage_client, | ||
) | ||
|
||
@_add_local_storage_error_hint | ||
async def open_request_queue( | ||
self, | ||
*, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't we move the decorator to a dedicated private module, perhaps apify._utils?