Skip to content

Commit

Permalink
cleaned up exception handling to print exception in the log output if…
Browse files Browse the repository at this point in the history
… the wrapper is in the process list
  • Loading branch information
georgemccabe committed Aug 26, 2020
1 parent f39becb commit c99a9bf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
8 changes: 5 additions & 3 deletions metplus/wrappers/cyclone_plotter_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@

# handle if module can't be loaded to run wrapper
wrapper_cannot_run = False
exception_err = ''
try:
import matplotlib.pyplot as plt
import matplotlib.ticker as mticker
import cartopy.crs as ccrs
import cartopy.feature as cfeature
from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER
except:
except Exception as e:
wrapper_cannot_run = True
exception_err = e

import produtil.setup

Expand All @@ -39,8 +41,8 @@ def __init__(self, config, logger):
super().__init__(config, logger)

if wrapper_cannot_run:
self.log_error("Cannot run CyclonePlotter wrapper due to import errors. "
"matplotlib and cartopy are required to run.")
self.log_error(f"{exception_err}\n")
self.log_error("Cannot run CyclonePlotter wrapper due to import errors.")
return

self.input_data = self.config.getdir('CYCLONE_PLOTTER_INPUT_DIR')
Expand Down
9 changes: 5 additions & 4 deletions metplus/wrappers/make_plots_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@

# handle if module can't be loaded to run wrapper
wrapper_cannot_run = False
exception_err = ''
try:
from ush.plotting_scripts import plot_util
except:
except Exception as e:
wrapper_cannot_run = True

exception_err = e

class MakePlotsWrapper(CommandBuilder):
"""! Wrapper to used to filter make plots from MET data
Expand Down Expand Up @@ -73,8 +74,8 @@ def __init__(self, config, logger):
super().__init__(config, logger)

if wrapper_cannot_run:
self.log_error("Cannot run CyclonePlotter wrapper due to import errors. "
"matplotlib and cartopy are required to run.")
self.log_error(f"{exception_err}\n")
self.log_error("Cannot run MakePlots wrapper due to import errors.")
return

def get_command(self):
Expand Down

0 comments on commit c99a9bf

Please sign in to comment.