From 0bfa494f62d5ecf5b3a77ac758df8be625655f90 Mon Sep 17 00:00:00 2001 From: Ludwig Schneider Date: Thu, 1 Dec 2022 09:07:01 -0600 Subject: [PATCH] Extract URL when UniqueNodeError is thrown --- src/cript/api/rest.py | 4 +++- src/cript/data_model/exceptions.py | 20 ++++++++++++++++++++ src/cript/storage_clients/globus.py | 6 +++++- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/cript/api/rest.py b/src/cript/api/rest.py index c82188e..94a63e3 100644 --- a/src/cript/api/rest.py +++ b/src/cript/api/rest.py @@ -56,7 +56,9 @@ def __init__(self, host: str = None, token: str = None, tls: bool = True): try: response = self.session.get(f"{self.url}/session-info/") except Exception as e: - raise APIError("Connection API failed, please review your host and token") from e + raise APIError( + "Connection API failed, please review your host and token" + ) from e if response.status_code == 200: response_json = response.json() self.latest_api_version = response_json["latest_version"] diff --git a/src/cript/data_model/exceptions.py b/src/cript/data_model/exceptions.py index 68e2c92..b982da0 100644 --- a/src/cript/data_model/exceptions.py +++ b/src/cript/data_model/exceptions.py @@ -1,3 +1,5 @@ +import re +import warnings from cript.exceptions import CRIPTError @@ -9,6 +11,24 @@ class UniqueNodeError(CRIPTError): def __init__(self, message): self.message = message + self.existing_url = None + url_find_pattern = ( + r"[(https://)|\w]*?[\w]*\.[-/\w]*\.\w*[(/{1})]?[#-\./\w]*[(/{1,})]?" + ) + all_urls = re.findall(url_find_pattern, message) + if len(all_urls) > 0: + if len(all_urls) > 1: + warning.warn( + "UniqueNodeError found more than one possible URL of a unique node. Please report this bug here: https://github.com/C-Accel-CRIPT/cript/issues Thank you." + ) + self.existing_url = all_urls[0] + while self.existing_url[-1] == ".": + self.existing_url = self.existing_url[:-1] + + if self.existing_url is None: + warnings.warn( + "UniqueNodeError failed to extract unique URL of existing node, please report this bug here: https://github.com/C-Accel-CRIPT/cript/issues Thank you." + ) def __str__(self): return self.message diff --git a/src/cript/storage_clients/globus.py b/src/cript/storage_clients/globus.py index 5e68aba..7ab06d0 100644 --- a/src/cript/storage_clients/globus.py +++ b/src/cript/storage_clients/globus.py @@ -6,7 +6,11 @@ from globus_sdk.scopes import ScopeBuilder from cript.data_model.nodes.base_node import BaseNode -from cript.storage_clients.exceptions import InvalidAuthCode, FileUploadError, FileDownloadError +from cript.storage_clients.exceptions import ( + InvalidAuthCode, + FileUploadError, + FileDownloadError, +) logger = getLogger(__name__)