Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository 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
Michiel Cottaar
fslpy
Commits
39d5f1d7
Commit
39d5f1d7
authored
7 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
Error message can be suppressed with reportIfError context manager
parent
fb0e54d8
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
fsl/utils/status.py
+15
-8
15 additions, 8 deletions
fsl/utils/status.py
with
15 additions
and
8 deletions
fsl/utils/status.py
+
15
−
8
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
...
...
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