diff --git a/sleap/gui/commands.py b/sleap/gui/commands.py index 93e382088..062cf0f76 100644 --- a/sleap/gui/commands.py +++ b/sleap/gui/commands.py @@ -3546,18 +3546,11 @@ def get_and_verify_enough_instances( require_multiple_views=True, ) return instances - except ValueError: - # If not enough views or instances, then return - message = ( - "One or less instances found for frame " - f"{frame_idx} in {session.camera_cluster}. " - "Multiple instances accross multiple views needed to triangulate. " - "Skipping triangulation and reprojection." - ) - if show_dialog and context is not None: - QtWidgets.QMessageBox.warning(context.app, "Triangulation", message) - else: - logger.warning(message) + except Exception as e: + # If not enough views, instances or some other error, then return + message = str(e) + message += "\n\tSkipping triangulation and reprojection." + logger.warning(message) return False @staticmethod @@ -3622,6 +3615,14 @@ def get_instances_across_views( instances are found. """ + def _message(views: bool): + views_or_instances = "views" if views else "instances" + return ( + f"One or less {views_or_instances} found for frame " + f"{frame_idx} in {session.camera_cluster}. " + "Multiple instances accross multiple views needed to triangulate." + ) + # Get all views at this frame index views: Dict[ Camcorder, "LabeledFrame" @@ -3633,10 +3634,7 @@ def get_instances_across_views( # If not enough views, then raise error if len(views) <= 1 and require_multiple_views: - raise ValueError( - "One or less views found for frame " - f"{frame_idx} in {session.camera_cluster}." - ) + raise ValueError(_message(views=True)) # Find all instance accross all views instances: Dict[Camcorder, "Instance"] = {} @@ -3647,10 +3645,7 @@ def get_instances_across_views( # If not enough instances for multiple views, then raise error if len(instances) <= 1 and require_multiple_views: - raise ValueError( - "One or less instances found for frame " - f"{frame_idx} in {session.camera_cluster}." - ) + raise ValueError(_message(views=False)) return instances diff --git a/tests/gui/test_commands.py b/tests/gui/test_commands.py index 35bef05d1..c20af8614 100644 --- a/tests/gui/test_commands.py +++ b/tests/gui/test_commands.py @@ -1273,7 +1273,7 @@ def test_triangulate_session_do_action(multiview_min_session_labels: Labels): def test_triangulate_session(multiview_min_session_labels: Labels): - """Test `TriangulateSession`, if""" + """Test `TriangulateSession`.""" labels = multiview_min_session_labels session = labels.sessions[0]