Skip to content

Commit

Permalink
fix(paramserver): raise exception during download when trees not found
Browse files Browse the repository at this point in the history
When no matching tree names are found in download_configurations, the
code will now raise a ConfigNotFoundException. This will assure that
clients get a proper error instead of not knowing what happened.

Wrike Ticket: https://www.wrike.com/open.htm?id=1182864968
  • Loading branch information
pallabpain committed Jan 19, 2024
1 parent 78c17a8 commit 5c77401
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 4 additions & 1 deletion rapyuta_io/clients/paramserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import hashlib
import mimetypes

from rapyuta_io.utils import RestClient, InvalidParameterException
from rapyuta_io.utils import RestClient, InvalidParameterException, ConfigNotFoundException
from rapyuta_io.utils.rest_client import HttpMethod
from rapyuta_io.utils.settings import PARAMSERVER_API_TREE_PATH, PARAMSERVER_API_TREEBLOBS_PATH, PARAMSERVER_API_FILENODE_PATH
from rapyuta_io.utils.utils import create_auth_header, prepend_bearer_to_auth_token, get_api_response_data, \
Expand Down Expand Up @@ -266,6 +266,9 @@ def download_configurations(self, rootdir, tree_names, delete_existing_trees):
if tree_names:
api_tree_names = [tree_name for tree_name in api_tree_names if tree_name in tree_names]

if not api_tree_names:
raise ConfigNotFoundException('One or more trees not found')

blob_temp_dir = tempfile.mkdtemp()

blob_files = self.get_blob_data(api_tree_names)
Expand Down
8 changes: 5 additions & 3 deletions rapyuta_io/rio_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,16 +643,18 @@ def download_configurations(self, rootdir, tree_names=None, delete_existing_tree
Following example demonstrates how to use download_configurations and handle errors.
>>> from rapyuta_io import Client
>>> from rapyuta_io.utils.error import APIError, InternalServerError
>>> from rapyuta_io.utils.error import APIError, InternalServerError, ConfigNotFoundException
>>> client = Client(auth_token='auth_token', project='project_guid')
>>> try:
... client.download_configurations('path/to/destination_dir',
... tree_names=['config_tree1', 'config_tree2'],
... delete_existing_trees=True)
... except (APIError, InternalServerError) as e:
... print 'failed API request', e.tree_path, e
... print('failed API request', e.tree_path, e)
except ConfigNotFoundException as e:
print ('config not found')
... except (IOError, OSError) as e:
... print 'failed file/directory creation', e
... print('failed file/directory creation', e)
"""
return self._paramserver_client.download_configurations(rootdir, tree_names, delete_existing_trees)
Expand Down

0 comments on commit 5c77401

Please sign in to comment.