From 5c774014503171b5dd2de50df27b950e531f2a79 Mon Sep 17 00:00:00 2001 From: Pallab Pain Date: Fri, 19 Jan 2024 22:25:18 +0530 Subject: [PATCH] fix(paramserver): raise exception during download when trees not found 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 --- rapyuta_io/clients/paramserver.py | 5 ++++- rapyuta_io/rio_client.py | 8 +++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/rapyuta_io/clients/paramserver.py b/rapyuta_io/clients/paramserver.py index 827bd030..6781aa1b 100644 --- a/rapyuta_io/clients/paramserver.py +++ b/rapyuta_io/clients/paramserver.py @@ -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, \ @@ -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) diff --git a/rapyuta_io/rio_client.py b/rapyuta_io/rio_client.py index 96d48ef9..7c70d0ff 100644 --- a/rapyuta_io/rio_client.py +++ b/rapyuta_io/rio_client.py @@ -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)