Skip to content
Snippets Groups Projects
Commit 8b510078 authored by florian's avatar florian
Browse files

ENH: Remove all get_something methods from exceptions.py

parent 0ca5c074
No related branches found
No related tags found
No related merge requests found
......@@ -209,105 +209,24 @@ class TransactionError(CaosDBException):
return self
elif isinstance(error, EntityError):
self.errors.append(error)
self.entities.append(error.get_entity())
self.entities.append(error.entity)
self.all_errors.add(error)
self.all_errors.update(error.get_all_errors())
self.all_entities.add(error.get_entity())
self.all_entities.update(error.get_all_entities())
self.all_errors.update(error.all_errors)
self.all_entities.add(error.entity)
self.all_entities.update(error.all_entities)
return self
else:
raise TypeError(
"Argument is to be an EntityError or a list of EntityErrors.")
def get_errors(self):
"""Return a list of all direct children of this error."""
return self.errors
def get_all_errors(self):
"""Return a set of all direct and inidrect children of this error."""
return self.all_errors
def get_entities(self):
"""Return a list of all entities causing direct child errors."""
return self.entities
def get_all_entities(self):
"""Return a set of all entities causing direct and indirect child
errors.
"""
return self.all_entities
def get_container(self):
"""Return the Container object that contained the problematic
entities.
Returns
-------
Container
Either the container that caused this error (which
contains at least one faulty entity) or, if none was given
during construction, a new container containing
self.entities instead.
"""
if self.container is not None:
return self.container
from caosdb.common.models import Container
return Container().extend(self.entities)
def get_error(self):
"""If this Transaction error was caused by exactly one EntityError,
return this error. Raise an AmbiguityException otherwise.
"""
if len(self.errors) == 1:
return self.errors[0].get_error()
else:
raise AmbiguityException(
"This TransactionError was caused by more than one EntityError."
)
def get_entity(self):
"""If this TransactionError was caused by exactly one EntityError,
return the entity causing that error. Raise and
AmbiguityException otherwise.
"""
if len(self.entities) == 1:
return self.entities[0]
else:
raise AmbiguityException(
"This TransActionError was caused by more than one EntityError."
)
def get_code(self):
"""In the special case of a container with at least one error message
with an integer code, return that code. Return None
otherwise.
"""
if self.container is not None and self.container.get_errors() is not None:
for err in self.container.get_errors():
if err.code is not None:
return err.code
return None
def _repr_reasons(self, indent):
if self.get_errors() is not None and len(self.get_errors()) > 0:
if self.errors is not None and len(self.errors) > 0:
ret = "\n" + indent + " +--| REASONS |--"
for err in self.get_errors():
for err in self.errors:
ret += '\n' + indent + ' | -> ' + \
err.__str__(indent=indent + ' |')
ret += "\n" + indent + " +----------------"
......@@ -354,25 +273,11 @@ class EntityError(TransactionError):
else:
self.msg = str(error)
def get_entity(self):
"""Return the entity causing this error."""
return self.entity
def get_error(self):
"""Return this error message as attached by the server."""
return self.error
@property
def description(self):
"""The description of the error."""
return self.error.description if self.error is not None else None
def get_code(self):
"""The code of the error."""
return self.error.code if self.error is not None else None
def _repr_head(self, indent):
if hasattr(self, 'entity') and self.entity is not None:
return (str(type(self.entity).__name__).upper() + " (id: " +
......@@ -388,17 +293,17 @@ class UniqueNamesError(EntityError):
class UnqualifiedParentsError(EntityError):
"""This entity has unqualified parents (call 'get_errors()' for a list
of errors of the parent entities or 'get_entities()' for a list of
parent entities with errors).
"""This entity has unqualified parents (see 'errors' attribute for a
list of errors of the parent entities or 'entities' attribute for
a list of parent entities with errors).
"""
class UnqualifiedPropertiesError(EntityError):
"""This entity has unqualified properties (call 'get_errors()' for a
list of errors of the properties or 'get_entities()' for a list of
properties with errors).
"""This entity has unqualified properties (see 'errors' attribute for
a list of errors of the properties or 'entities' attribute for a
list of properties with errors).
"""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment