async def test_run_error_handling(self, mock_sync, mock_sync_job, mock_sync_dag, mock_user, mock_collection, mock_source_connection):
        """Test error handling during sync run."""
        # Arrange
        mock_db_context = AsyncMock()
        mock_db = AsyncMock(spec=AsyncSession)
        mock_db_context.__aenter__.return_value = mock_db
        test_error = Exception("Test error")

        # Mock get_db_context
        with patch("airweave.core.sync_service.get_db_context") as mock_get_db_context:
            mock_get_db_context.return_value = mock_db_context

            # Mock SyncFactory.create_orchestrator to raise an exception
            with patch(
                "airweave.core.sync_service.SyncFactory.create_orchestrator"
            ) as mock_create_orchestrator:
                mock_create_orchestrator.side_effect = test_error

                # Mock logger.error
                with patch("airweave.core.sync_service.logger.error") as mock_logger_error:
                    # Act & Assert
                    with patch("airweave.core.sync_service.sync_job_service.update_status") as mock_update_status:
                        mock_update_status.return_value = None
                        service = SyncService()
                        with pytest.raises(Exception) as excinfo:
                            await service.run(
                                sync=mock_sync,
                                sync_job=mock_sync_job,
                                dag=mock_sync_dag,
                                collection=mock_collection,
                                source_connection=mock_source_connection,
                                current_user=mock_user,
                            )

                    # Verify the exception was logged and re-raised
                    assert excinfo.value == test_error
                    mock_logger_error.assert_called_once()
                    assert "Error during sync" in mock_logger_error.call_args[0][0]
Test error handling during sync run.
backend/tests/unit/platform/sync/test_service.py