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
84ee2aea
Commit
84ee2aea
authored
5 years ago
by
Henrik tom Wörden
Browse files
Options
Downloads
Patches
Plain Diff
MAINT: whitespace changes
parent
42183bc2
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/caosdb/exceptions.py
+27
-0
27 additions, 0 deletions
src/caosdb/exceptions.py
with
27 additions
and
0 deletions
src/caosdb/exceptions.py
+
27
−
0
View file @
84ee2aea
...
...
@@ -72,6 +72,7 @@ class ServerErrorException(CaosDBException):
xml
=
etree
.
fromstring
(
body
)
error
=
xml
.
xpath
(
'
/Response/Error
'
)[
0
]
msg
=
error
.
get
(
"
description
"
)
if
error
.
text
is
not
None
:
msg
=
msg
+
"
\n\n
"
+
error
.
text
CaosDBException
.
__init__
(
self
,
msg
)
...
...
@@ -114,15 +115,18 @@ class TransactionError(CaosDBException):
def
_calc_bases
(
self
):
types
=
dict
()
# collect each class once
for
err
in
self
.
errors
:
types
[
id
(
type
(
err
))]
=
type
(
err
)
# delete redundant super classes
if
len
(
types
.
values
())
>
1
:
# remove TransactionError
try
:
del
types
[
id
(
TransactionError
)]
except
KeyError
:
pass
if
len
(
types
.
values
())
>
1
:
# remove EntityError
try
:
...
...
@@ -131,10 +135,13 @@ class TransactionError(CaosDBException):
pass
ret
=
()
for
t
in
types
.
values
():
ret
+=
(
t
,)
if
ret
==
():
ret
=
(
type
(
self
),)
return
ret
def
__init__
(
self
,
container
=
None
,
error
=
None
,
msg
=
None
):
...
...
@@ -145,6 +152,7 @@ class TransactionError(CaosDBException):
def
print_errs
(
self
):
print
(
self
)
for
err
in
self
.
errors
:
err
.
print_errs
()
...
...
@@ -158,6 +166,7 @@ class TransactionError(CaosDBException):
newinstance
=
newtype
(
container
=
self
.
container
,
error
=
self
.
msg
)
newinstance
.
errors
=
self
.
errors
newinstance
.
get_entities
=
self
.
get_entities
return
newinstance
def
get_container
(
self
):
...
...
@@ -165,6 +174,7 @@ class TransactionError(CaosDBException):
@return: The container that raised this TransactionError during the last
transaction.
'''
return
self
.
container
def
add_error
(
self
,
error
):
...
...
@@ -177,12 +187,15 @@ class TransactionError(CaosDBException):
@return: self.
"""
if
hasattr
(
error
,
"
__iter__
"
):
for
e
in
error
:
self
.
add_error
(
e
)
return
self
elif
isinstance
(
error
,
TransactionError
):
self
.
errors
.
append
(
error
)
return
self
else
:
raise
TypeError
(
...
...
@@ -192,17 +205,21 @@ class TransactionError(CaosDBException):
'''
@return: A list of all EntityError objects.
'''
if
hasattr
(
self
,
'
errors
'
):
return
self
.
errors
return
None
def
_repr_reasons
(
self
,
indent
):
if
self
.
get_errors
()
is
not
None
and
len
(
self
.
get_errors
())
>
0
:
ret
=
"
\n
"
+
indent
+
"
+--| REASONS |--
"
for
c
in
self
.
get_errors
():
ret
+=
'
\n
'
+
indent
+
'
| ->
'
+
\
c
.
__str__
(
indent
=
indent
+
'
|
'
)
ret
+=
"
\n
"
+
indent
+
"
+----------------
"
return
ret
else
:
return
''
...
...
@@ -214,6 +231,7 @@ class TransactionError(CaosDBException):
def
__str__
(
self
,
indent
=
''
):
ret
=
self
.
_repr_head
(
indent
=
indent
)
ret
+=
self
.
_repr_reasons
(
indent
=
indent
)
return
ret
def
__repr__
(
self
):
...
...
@@ -224,8 +242,10 @@ class TransactionError(CaosDBException):
@return: A list of all Entity objects with errors.
'''
ret
=
[]
if
hasattr
(
self
,
'
get_entity
'
)
and
self
.
get_entity
()
is
not
None
:
ret
.
append
(
self
.
get_entity
())
for
error
in
self
.
errors
:
if
hasattr
(
error
,
'
get_entity
'
):
if
error
.
get_entity
()
not
in
ret
:
...
...
@@ -247,10 +267,12 @@ class EntityError(TransactionError):
if
len
(
t
)
>
1
:
ret
=
()
'''
remove EntityError
'''
for
i
in
range
(
len
(
t
)):
if
t
[
i
]
!=
EntityError
:
ret
+=
(
t
[
i
],)
t
=
ret
return
t
def
_convert
(
self
):
...
...
@@ -260,12 +282,14 @@ class EntityError(TransactionError):
setattr
(
newinstance
,
'
msg
'
,
self
.
msg
)
setattr
(
newinstance
,
'
errors
'
,
self
.
errors
)
setattr
(
newinstance
,
'
container
'
,
self
.
container
)
return
newinstance
def
__init__
(
self
,
error
=
None
,
container
=
None
,
entity
=
None
):
TransactionError
.
__init__
(
self
,
container
=
container
)
self
.
error
=
error
self
.
entity
=
entity
if
error
is
not
None
and
hasattr
(
error
,
"
encode
"
):
self
.
msg
=
error
elif
error
is
not
None
and
hasattr
(
error
,
'
description
'
):
...
...
@@ -279,8 +303,10 @@ class EntityError(TransactionError):
'''
@return: The entity that caused this error.
'''
if
hasattr
(
self
,
'
entity
'
):
return
self
.
entity
return
None
@property
...
...
@@ -294,6 +320,7 @@ class EntityError(TransactionError):
'''
@return: Error Message object of this Error.
'''
return
self
.
error
def
_repr_head
(
self
,
indent
):
...
...
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