Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-pylib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-pylib
Commits
8b510078
Commit
8b510078
authored
4 years ago
by
florian
Browse files
Options
Downloads
Patches
Plain Diff
ENH: Remove all get_something methods from exceptions.py
parent
0ca5c074
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/caosdb/exceptions.py
+13
-108
13 additions, 108 deletions
src/caosdb/exceptions.py
with
13 additions
and
108 deletions
src/caosdb/exceptions.py
+
13
−
108
View file @
8b510078
...
...
@@ -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).
"""
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment