Skip to content

Commit cb792aa

Browse files
committed
try except statements added to IMRO uploader to prevent app crashing
1 parent 20e1da7 commit cb792aa

3 files changed

Lines changed: 21 additions & 13 deletions

File tree

channelmap_generator/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77

88
from .backend import *
99

10-
__version__ = "0.3.5"
10+
__version__ = "0.3.6"
1111
__author__ = "Maxime Beau"
1212
__email__ = "maxime@princeton.edu"

channelmap_generator/gui/gui.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -688,14 +688,18 @@ def apply_uploaded_imro(self):
688688
imro_file_content = imro_file_content.decode("utf-8")
689689
imro_list = imro.parse_imro_file(imro_file_content.strip())
690690

691-
(imro_electrodes,
692-
self.probe_type, # probe_type value is a monitored param - simply setting its value will update the plot
693-
self.probe_subtype,
694-
self.reference_id,
695-
self.ap_gain_input.value,
696-
self.lf_gain_input.value,
697-
self.hardware_hp_filter_on,
698-
) = imro.parse_imro_list(imro_list)
691+
try:
692+
(imro_electrodes,
693+
self.probe_type, # probe_type value is a monitored param - simply setting its value will update the plot
694+
self.probe_subtype,
695+
self.reference_id,
696+
self.ap_gain_input.value,
697+
self.lf_gain_input.value,
698+
self.hardware_hp_filter_on,
699+
) = imro.parse_imro_list(imro_list)
700+
except:
701+
pn.state.notifications.error("Failed to parse uploaded imro file.")
702+
return
699703

700704
self.electrodes.clear_selection()
701705
for shank_id, electrode_id in imro_electrodes:

channelmap_generator/utils/imro.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,17 +181,21 @@ def parse_imro_list(imro_list):
181181
def ref_id_to_string(reference_id, probe_subtype):
182182
ref_map = {v: k for k, v in REF_ELECTRODES[probe_subtype].items() if k != "Join Tips"}
183183
if reference_id not in ref_map:
184-
pn.state.notifications.error(f"Unexpected reference id {reference_id} for probe subtype {probe_subtype}!",
184+
error_message = f"Unexpected reference id {reference_id} for probe subtype {probe_subtype}!"
185+
pn.state.notifications.error(error_message,
185186
duration=10_000)
186-
assert reference_id in ref_map,\
187-
f"Unexpected reference id {reference_id} for probe subtype {probe_subtype}!"
187+
raise AssertionError(error_message)
188188
return ref_map[reference_id]
189189

190+
190191
def check_entry_elements(n_expected_elements, entry, probe_type):
191192
n_entry_elements = len(entry)
192193
if n_entry_elements != n_expected_elements:
193-
pn.state.notifications.error(f"Corrupt .imro file - IMRO table entries for {probe_type} probes should have {n_expected_elements} elements, not {n_entry_elements}.",
194+
error_message = f"Corrupt .imro file - IMRO table entries for {probe_type} probes should have {n_expected_elements} elements, not {n_entry_elements}."
195+
pn.state.notifications.error(error_message,
194196
duration=10_000)
197+
raise AssertionError(error_message)
198+
195199

196200
def generate_imro_channelmap(
197201
probe_type,

0 commit comments

Comments
 (0)