Skip to content

Commit

Permalink
Manage exceptions when reading from database
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiodsf committed May 13, 2024
1 parent 1428d7d commit a4387e5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
5 changes: 4 additions & 1 deletion seiscat/editdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,10 @@ def editdb(config):
version = args.version
if eventid == 'ALL':
eventid = None
fields, rows = read_fields_and_rows_from_db(config, eventid, version)
try:
fields, rows = read_fields_and_rows_from_db(config, eventid, version)
except (FileNotFoundError, ValueError) as msg:
err_exit(msg)
if not rows:
if eventid and version:
msg = f'Event {eventid} version {version} not found in database'
Expand Down
5 changes: 4 additions & 1 deletion seiscat/plot_map_cartopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,10 @@ def plot_catalog_map_with_cartopy(config):
def redraw_gridlines(ax):
ax.gridlines(**g_kwargs)
ax.callbacks.connect('xlim_changed', redraw_gridlines)
events = read_events_from_db(config)
try:
events = read_events_from_db(config)
except (FileNotFoundError, ValueError) as msg:
err_exit(msg)
scale = config['args'].scale
plot_version_number = config['args'].allversions
_plot_events(ax, events, scale, plot_version_number)
Expand Down
19 changes: 11 additions & 8 deletions seiscat/print.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,14 @@ def print_catalog(config):
:param config: config object
"""
args = config['args']
if args.format == 'stats':
_print_catalog_stats(config)
elif args.format == 'table':
_print_catalog_table(config, eventid=args.eventid)
elif args.format == 'csv':
_print_catalog_csv(config, eventid=args.eventid)
else:
err_exit(f'Unknown format "{args.format}"')
try:
if args.format == 'stats':
_print_catalog_stats(config)
elif args.format == 'table':
_print_catalog_table(config, eventid=args.eventid)
elif args.format == 'csv':
_print_catalog_csv(config, eventid=args.eventid)
else:
err_exit(f'Unknown format "{args.format}"')
except (FileNotFoundError, ValueError) as msg:
err_exit(msg)

0 comments on commit a4387e5

Please sign in to comment.