Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
synergy
o3skim
Commits
e425c376
Commit
e425c376
authored
Dec 07, 2020
by
BorjaEst
Browse files
Add default return value to error log decorator
parent
7e2909b8
Changes
2
Hide whitespace changes
Inline
Side-by-side
o3skim/standardization.py
View file @
e425c376
...
...
@@ -26,7 +26,8 @@ vmro3_standard_coordinates = [
]
@
utils
.
return_on_failure
(
"Error when loading '{0}'"
.
format
(
tco3_standard_name
))
@
utils
.
return_on_failure
(
"Error when loading '{0}'"
.
format
(
tco3_standard_name
),
xr
.
Dataset
())
def
__load_tco3
(
name
,
paths
,
coordinates
):
"""Loads and standarises the tco3 data"""
logger
.
debug
(
"Standard loading of '{0}' data"
.
format
(
tco3_standard_name
))
...
...
@@ -38,7 +39,8 @@ def __load_tco3(name, paths, coordinates):
return
dataset
.
mean
(
dim
=
tco3_mean_coordinate
)
@
utils
.
return_on_failure
(
"Error when loading '{0}'"
.
format
(
vmro3_standard_name
))
@
utils
.
return_on_failure
(
"Error when loading '{0}'"
.
format
(
vmro3_standard_name
),
xr
.
Dataset
())
def
__load_vmro3
(
name
,
paths
,
coordinates
):
"""Loads and standarises the vmro3 data"""
logger
.
debug
(
"Standard loading of '{0}' data"
.
format
(
vmro3_standard_name
))
...
...
o3skim/utils.py
View file @
e425c376
...
...
@@ -35,12 +35,15 @@ def cd(newdir):
logger
.
debug
(
"Restore directory: '%s'"
,
prevdir
)
def
return_on_failure
(
message
):
def
return_on_failure
(
message
,
default
=
None
):
"""Decorator to do not break but log. Note that the error stack
is printed as well to do not lose relevant information.
:param message: Additional message to log when the function fails.
:type message: str
:param default: Value to return if fails.
:type default: any or None, optional
"""
def
decorate
(
function
):
def
applicator
(
*
args
,
**
kwargs
):
...
...
@@ -49,6 +52,7 @@ def return_on_failure(message):
except
:
# Log error with stack using root (not utils)
logging
.
error
(
message
,
exc_info
=
True
)
return
default
return
applicator
return
decorate
...
...
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