Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Michiel Cottaar
fslpy
Commits
39d5f1d7
Commit
39d5f1d7
authored
Apr 05, 2017
by
Paul McCarthy
Browse files
Error message can be suppressed with reportIfError context manager
parent
fb0e54d8
Changes
1
Hide whitespace changes
Inline
Side-by-side
fsl/utils/status.py
View file @
39d5f1d7
...
...
@@ -139,9 +139,15 @@ def reportError(title, msg, err):
@
contextlib
.
contextmanager
def
reportIfError
(
title
,
msg
,
raiseError
=
True
):
def
reportIfError
(
title
,
msg
,
raiseError
=
True
,
report
=
True
):
"""A context manager which calls :func:`reportError` if the enclosed code
raises an ``Exception``.
:arg raiseError: If ``True``, the ``Exception`` which was raised is
propagated upwards.
:arg report: Defaults to ``True``. If ``False``, an error message
is logged, but :func:`reportError` is not called.
"""
try
:
yield
...
...
@@ -150,21 +156,22 @@ def reportIfError(title, msg, raiseError=True):
log
.
error
(
'{}: {}'
.
format
(
title
,
msg
),
exc_info
=
True
)
reportError
(
title
,
msg
,
e
)
if
report
:
reportError
(
title
,
msg
,
e
)
if
raiseError
:
raise
def
reportErrorDecorator
(
title
,
msg
):
"""A decorator which
calls :func:`reportError` if
the decorated function
raises an ``Exception`
`.
def
reportErrorDecorator
(
*
args
,
**
kwargs
):
"""A decorator which
wraps
the decorated function
with
:func:`reportIfError
`.
"""
def
decorator
(
func
):
def
wrapper
(
*
args
,
**
kwargs
):
with
reportIfError
(
title
,
msg
):
func
(
*
args
,
**
kwargs
)
def
wrapper
(
*
w
args
,
**
w
kwargs
):
with
reportIfError
(
*
args
,
**
kwargs
):
func
(
*
w
args
,
**
w
kwargs
)
return
wrapper
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment