Skip to content

Commit

Permalink
get rid of re-raise with traceback and migrate to the 'raise from' me…
Browse files Browse the repository at this point in the history
…thod
  • Loading branch information
StefanBogdan committed Aug 12, 2021
1 parent e03937a commit 4b13843
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 144 deletions.
4 changes: 1 addition & 3 deletions weaviate/batch/crud_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,7 @@ def _create_data(self,
else:
break
except RequestsConnectionError as conn_err:
message = str(conn_err)\
+ ' Connection error, batch was not added to weaviate.'
raise type(conn_err)(message).with_traceback(sys.exc_info()[2])
raise RequestsConnectionError('Batch was not added to weaviate.') from conn_err
except ReadTimeout:
message = (
f"The '{data_type}' creation was cancelled because it took "
Expand Down
6 changes: 2 additions & 4 deletions weaviate/classification/classification.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""
Classification class definition.
"""
import sys
import validators
from weaviate import UnexpectedStatusCodeException, RequestsConnectionError
from weaviate.connect import Connection
Expand Down Expand Up @@ -70,9 +69,8 @@ def get(self, classification_uuid: str) -> dict:
path='/classifications/' + classification_uuid,
)
except RequestsConnectionError as conn_err:
message = str(conn_err)\
+ ' Connection error, classification status could not be retrieved.'
raise type(conn_err)(message).with_traceback(sys.exc_info()[2])
raise RequestsConnectionError('Classification status could not be retrieved.')\
from conn_err
if response.status_code == 200:
return response.json()
raise UnexpectedStatusCodeException("Get classification status", response)
Expand Down
9 changes: 3 additions & 6 deletions weaviate/classification/config_builder.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""
ConfigBuilder class definition.
"""
import sys
import time
from typing import Dict, Any
from weaviate.exceptions import UnexpectedStatusCodeException, RequestsConnectionError
Expand Down Expand Up @@ -256,9 +255,9 @@ def _start(self) -> dict:
Raises
------
requests.exceptions.ConnectionError
requests.ConnectionError
If the network connection to weaviate fails.
weaviate.exceptions.UnexpectedStatusCodeException
weaviate.UnexpectedStatusCodeException
Unexpected error.
"""

Expand All @@ -268,9 +267,7 @@ def _start(self) -> dict:
weaviate_object=self._config
)
except RequestsConnectionError as conn_err:
message = str(conn_err)\
+ ' Connection error, classification may not started.'
raise type(conn_err)(message).with_traceback(sys.exc_info()[2])
raise RequestsConnectionError('Classification may not started.') from conn_err
if response.status_code == 201:
return response.json()
raise UnexpectedStatusCodeException("Start classification", response)
Expand Down
18 changes: 4 additions & 14 deletions weaviate/contextionary/crud_contextionary.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""
Contextionary class definition.
"""
import sys
from weaviate import RequestsConnectionError, UnexpectedStatusCodeException
from weaviate.connect import Connection

Expand Down Expand Up @@ -85,9 +84,8 @@ def extend(self,
weaviate_object=extension,
)
except RequestsConnectionError as conn_err:
message = str(conn_err)\
+ ' Connection error, text2vec-contextionary could not be extended.'
raise type(conn_err)(message).with_traceback(sys.exc_info()[2])
raise RequestsConnectionError('text2vec-contextionary could not be extended.')\
from conn_err
if response.status_code == 200:
# Successfully extended
return
Expand Down Expand Up @@ -146,11 +144,8 @@ def get_concept_vector(self, concept: str) -> dict:
------
requests.ConnectionError
If the network connection to weaviate fails.
Exception
Unexpected exception that should be reported in an issue.
weaviate.UnexpectedStatusCodeException
If weaviate reports a none OK status.
AttributeError
"""

path = "/modules/text2vec-contextionary/concepts/" + concept
Expand All @@ -159,13 +154,8 @@ def get_concept_vector(self, concept: str) -> dict:
path=path
)
except RequestsConnectionError as conn_err:
message = str(conn_err)\
+ ' Connection error, text2vec-contextionary vector was not retrieved.'
raise type(conn_err)(message).with_traceback(sys.exc_info()[2])
except Exception as error:
message = str(error)\
+ ' Unexpected exception please report this exception in an issue.'
raise type(error)(message).with_traceback(sys.exc_info()[2])
raise RequestsConnectionError('text2vec-contextionary vector was not retrieved.')\
from conn_err
else:
if response.status_code == 200:
return response.json()
Expand Down
30 changes: 7 additions & 23 deletions weaviate/data/crud_data.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""
DataObject class definition.
"""
import sys
from typing import Union, Optional, List, Sequence
import validators
from weaviate.connect import Connection
Expand Down Expand Up @@ -119,10 +118,7 @@ def create(self,
weaviate_object=weaviate_obj
)
except RequestsConnectionError as conn_err:
message = str(conn_err)\
+ ' Connection error, object was not added to weaviate.'
raise type(conn_err)(message).with_traceback(sys.exc_info()[2])

raise RequestsConnectionError('Object was not added to Weaviate.') from conn_err
if response.status_code == 200:
return str(response.json()["id"])

Expand All @@ -132,11 +128,6 @@ def create(self,
object_does_already_exist = True
except KeyError:
pass
except Exception as error:
message = str(error)\
+ ' Unexpected exception please report this exception in an issue.'
raise type(error)(message).with_traceback(sys.exc_info()[2])

if object_does_already_exist:
raise ObjectAlreadyExistsException(str(uuid))
raise UnexpectedStatusCodeException("Creating object", response)
Expand Down Expand Up @@ -244,8 +235,7 @@ def update(self,
weaviate_object=weaviate_obj
)
except RequestsConnectionError as conn_err:
message = str(conn_err) + ' Connection error, object was not updated(REST PATCH).'
raise type(conn_err)(message).with_traceback(sys.exc_info()[2])
raise RequestsConnectionError('Object was not updated.') from conn_err
if response.status_code == 204:
# Successful merge
return
Expand Down Expand Up @@ -342,8 +332,7 @@ def replace(self,
weaviate_object=weaviate_obj
)
except RequestsConnectionError as conn_err:
message = str(conn_err) + ' Connection error, object was not replaced(REST PUT).'
raise type(conn_err)(message).with_traceback(sys.exc_info()[2])
raise RequestsConnectionError('Object was not replaced.') from conn_err
if response.status_code == 200:
# Successful update
return
Expand Down Expand Up @@ -449,9 +438,7 @@ def get(self,
try:
response = self._get_response(uuid, additional_properties, with_vector)
except RequestsConnectionError as conn_err:
message = str(conn_err) + ' Connection error when getting object/s'
raise type(conn_err)(message).with_traceback(sys.exc_info()[2])

raise RequestsConnectionError('Could not get object/s.') from conn_err
if response.status_code == 200:
return response.json()
if uuid is not None and response.status_code == 404:
Expand Down Expand Up @@ -508,9 +495,7 @@ def delete(self, uuid: str) -> None:
path="/objects/" + uuid,
)
except RequestsConnectionError as conn_err:
message = str(conn_err)\
+ ' Connection error, object could not be deleted.'
raise type(conn_err)(message).with_traceback(sys.exc_info()[2])
raise RequestsConnectionError('Object could not be deleted.') from conn_err
if response.status_code == 204:
# Successfully deleted
return
Expand Down Expand Up @@ -652,9 +637,8 @@ def validate(self,
weaviate_object=weaviate_obj
)
except RequestsConnectionError as conn_err:
message = str(conn_err)\
+ ' Connection error, object was not validated against weaviate.'
raise type(conn_err)(message).with_traceback(sys.exc_info()[2])
raise RequestsConnectionError('Object was not validated against weaviate.')\
from conn_err

result: dict = {
"error": None
Expand Down
17 changes: 3 additions & 14 deletions weaviate/data/references/crud_references.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
"""
Reference class definition.
"""
import sys
from typing import Union
from weaviate.connect import Connection
from weaviate import RequestsConnectionError, UnexpectedStatusCodeException
from weaviate.util import get_valid_uuid



class Reference:
"""
Reference class used to manipulate references within objects.
Expand Down Expand Up @@ -132,10 +130,7 @@ def delete(self,
weaviate_object=beacon
)
except RequestsConnectionError as conn_err:
message = str(conn_err)\
+ ' Connection error, did not delete reference.'
raise type(conn_err)(message).with_traceback(sys.exc_info()[2])

raise RequestsConnectionError('Reference was not deleted.') from conn_err
if response.status_code == 204:
return
raise UnexpectedStatusCodeException("Delete property reference to object", response)
Expand Down Expand Up @@ -259,10 +254,7 @@ def update(self,
weaviate_object=beacons
)
except RequestsConnectionError as conn_err:
message = str(conn_err)\
+ ' Connection error, did not update reference.'
raise type(conn_err)(message).with_traceback(sys.exc_info()[2])

raise RequestsConnectionError('Reference was not updated.') from conn_err
if response.status_code == 200:
return
raise UnexpectedStatusCodeException("Update property reference to object", response)
Expand Down Expand Up @@ -360,10 +352,7 @@ def add(self,
weaviate_object=beacons
)
except RequestsConnectionError as conn_err:
message = str(conn_err)\
+ ' Connection error, did not add reference.'
raise type(conn_err)(message).with_traceback(sys.exc_info()[2])

raise RequestsConnectionError('Reference was not added.') from conn_err
if response.status_code == 200:
return
raise UnexpectedStatusCodeException("Add property reference to object", response)
Expand Down
4 changes: 1 addition & 3 deletions weaviate/gql/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
GraphQL abstract class for GraphQL commands to inherit from.
"""
import json
import sys
from copy import deepcopy
from typing import Optional
from abc import ABC, abstractmethod
Expand Down Expand Up @@ -65,8 +64,7 @@ def do(self) -> dict:
weaviate_object={"query": query}
)
except RequestsConnectionError as conn_err:
message = str(conn_err) + ' Connection error, query was not successful.'
raise type(conn_err)(message).with_traceback(sys.exc_info()[2])
raise RequestsConnectionError('Query was not successful.') from conn_err
if response.status_code == 200:
return response.json() # success
raise UnexpectedStatusCodeException("Query was not successful", response)
Expand Down
5 changes: 1 addition & 4 deletions weaviate/gql/query.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""
GraphQL query module.
"""
import sys
from typing import List, Union
from weaviate.connect import Connection
from weaviate import UnexpectedStatusCodeException, RequestsConnectionError
Expand Down Expand Up @@ -146,9 +145,7 @@ def raw(self, gql_query: str) -> dict:
weaviate_object=json_query
)
except RequestsConnectionError as conn_err:
message = str(conn_err) + ' Connection error, query not executed.'
raise type(conn_err)(message).with_traceback(sys.exc_info()[2])

raise RequestsConnectionError('Query not executed.') from conn_err
if response.status_code == 200:
return response.json() # Successfully queried
raise UnexpectedStatusCodeException("GQL query failed", response)
21 changes: 8 additions & 13 deletions weaviate/schema/crud_schema.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""
Schema class definition.
"""
import sys
from typing import Union, Optional
from weaviate.connect import Connection
from weaviate.util import _get_dict_from_object, _is_sub_schema
Expand Down Expand Up @@ -177,8 +176,7 @@ def delete_class(self, class_name: str) -> None:
path=path
)
except RequestsConnectionError as conn_err:
message = str(conn_err) + ' Connection error, during deletion of class.'
raise type(conn_err)(message).with_traceback(sys.exc_info()[2])
raise RequestsConnectionError('Deletion of class.') from conn_err
if response.status_code != 200:
raise UnexpectedStatusCodeException("Delete class from schema", response)

Expand Down Expand Up @@ -277,9 +275,8 @@ def update_config(self, class_name: str, config: dict) -> None:
weaviate_object=new_class_schema
)
except RequestsConnectionError as conn_err:
message = str(conn_err)\
+ ' Connection error, class schema configuration could not be updated.'
raise type(conn_err)(message).with_traceback(sys.exc_info()[2])
raise RequestsConnectionError('Class schema configuration could not be updated.')\
from conn_err
if response.status_code != 200:
raise UnexpectedStatusCodeException("Update class schema configuration", response)

Expand Down Expand Up @@ -385,8 +382,7 @@ def get(self, class_name: str = None) -> dict:
path=path
)
except RequestsConnectionError as conn_err:
message = str(conn_err) + ' Connection error, schema could not be retrieved.'
raise type(conn_err)(message).with_traceback(sys.exc_info()[2])
raise RequestsConnectionError('Schema could not be retrieved.') from conn_err
if response.status_code != 200:
raise UnexpectedStatusCodeException("Get schema", response)
return response.json()
Expand Down Expand Up @@ -435,9 +431,8 @@ def _create_complex_properties_from_class(self, schema_class: dict) -> None:
weaviate_object=schema_property
)
except RequestsConnectionError as conn_err:
message = str(conn_err)\
+ ' Connection error, property may not have been created properly.'
raise type(conn_err)(message).with_traceback(sys.exc_info()[2])
raise RequestsConnectionError('Property may not have been created properly.')\
from conn_err
if response.status_code != 200:
raise UnexpectedStatusCodeException("Add properties to classes", response)

Expand Down Expand Up @@ -506,8 +501,8 @@ def _create_class_with_premitives(self, weaviate_class: dict) -> None:
weaviate_object=schema_class
)
except RequestsConnectionError as conn_err:
message = str(conn_err) + ' Connection error, class may not have been created properly.'
raise type(conn_err)(message).with_traceback(sys.exc_info()[2])
raise RequestsConnectionError('Class may not have been created properly.')\
from conn_err
if response.status_code != 200:
raise UnexpectedStatusCodeException("Create class", response)

Expand Down
Loading

0 comments on commit 4b13843

Please sign in to comment.