Skip to content

Commit 6a54323

Browse files
authored
refactor: wrap migration_iterator lambda in a try/except block (#773)
1 parent f48b363 commit 6a54323

File tree

1 file changed

+27
-21
lines changed

1 file changed

+27
-21
lines changed

tagstudio/src/qt/widgets/migration_modal.py

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -367,29 +367,35 @@ def migration_progress(self, skip_ui: bool = False):
367367
pb.setCancelButton(None)
368368
self.body_wrapper_01.layout().addWidget(pb)
369369

370-
iterator = FunctionIterator(self.migration_iterator)
371-
iterator.value.connect(
372-
lambda x: (
373-
pb.setLabelText(f"<h4>{x}</h4>"),
374-
self.update_sql_value_ui(show_msg_box=False)
375-
if x == Translations["json_migration.checking_for_parity"]
376-
else (),
377-
self.update_parity_ui()
378-
if x == Translations["json_migration.checking_for_parity"]
379-
else (),
370+
try:
371+
iterator = FunctionIterator(self.migration_iterator)
372+
iterator.value.connect(
373+
lambda x: (
374+
pb.setLabelText(f"<h4>{x}</h4>"),
375+
self.update_sql_value_ui(show_msg_box=False)
376+
if x == Translations["json_migration.checking_for_parity"]
377+
else (),
378+
self.update_parity_ui()
379+
if x == Translations["json_migration.checking_for_parity"]
380+
else (),
381+
)
380382
)
381-
)
382-
r = CustomRunnable(iterator.run)
383-
r.done.connect(
384-
lambda: (
385-
self.update_sql_value_ui(show_msg_box=not skip_ui),
386-
pb.setMinimum(1),
387-
pb.setValue(1),
388-
# Enable the finish button
389-
self.stack[1].buttons[4].setDisabled(False), # type: ignore
383+
r = CustomRunnable(iterator.run)
384+
r.done.connect(
385+
lambda: (
386+
self.update_sql_value_ui(show_msg_box=not skip_ui),
387+
pb.setMinimum(1),
388+
pb.setValue(1),
389+
# Enable the finish button
390+
self.stack[1].buttons[4].setDisabled(False), # type: ignore
391+
)
390392
)
391-
)
392-
QThreadPool.globalInstance().start(r)
393+
QThreadPool.globalInstance().start(r)
394+
except Exception as e:
395+
logger.error("[MigrationModal][Iterator] Error:", error=e)
396+
pb.setLabelText(f"<h4>{type(e).__name__}</h4>")
397+
pb.setMinimum(1)
398+
pb.setValue(1)
393399

394400
def migration_iterator(self):
395401
"""Iterate over the library migration process."""

0 commit comments

Comments
 (0)