diff --git a/packages/uipath-platform/pyproject.toml b/packages/uipath-platform/pyproject.toml index 78f8bc068..fdafe30cd 100644 --- a/packages/uipath-platform/pyproject.toml +++ b/packages/uipath-platform/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "uipath-platform" -version = "0.3.12" +version = "0.3.13" description = "HTTP client library for programmatic access to UiPath Platform" readme = { file = "README.md", content-type = "text/markdown" } requires-python = ">=3.11" diff --git a/packages/uipath-platform/src/uipath/platform/action_center/_tasks_service.py b/packages/uipath-platform/src/uipath/platform/action_center/_tasks_service.py index 627280deb..b61b2bf66 100644 --- a/packages/uipath-platform/src/uipath/platform/action_center/_tasks_service.py +++ b/packages/uipath-platform/src/uipath/platform/action_center/_tasks_service.py @@ -21,6 +21,7 @@ from ..common._folder_context import FolderContext, header_folder from ..common._models import Endpoint, RequestSpec from ..common._span_utils import _SpanUtils +from ..errors import AppNotFoundError from .task_schema import TaskSchema from .tasks import Task, TaskRecipient, TaskRecipientType @@ -997,7 +998,9 @@ def _extract_deployed_app( app for app in deployed_apps if app["deploymentTitle"] == app_name ] if len(filtered_apps_by_name) < 1: - raise Exception(f"App '{app_name}' was not found in the current tenant") + raise AppNotFoundError( + f"App '{app_name}' was not found in the current tenant" + ) # priority: app_folder_path -> app_folder_key -> self._folder_path -> self._folder_key candidates = [ @@ -1017,7 +1020,7 @@ def _extract_deployed_app( if app["deploymentFolder"][field] == value ) except StopIteration: - raise Exception( + raise AppNotFoundError( f"App '{app_name}' was not found in folder with {label} '{value}'" ) from StopIteration diff --git a/packages/uipath-platform/src/uipath/platform/errors/__init__.py b/packages/uipath-platform/src/uipath/platform/errors/__init__.py index 5ac51d326..53d34029e 100644 --- a/packages/uipath-platform/src/uipath/platform/errors/__init__.py +++ b/packages/uipath-platform/src/uipath/platform/errors/__init__.py @@ -3,6 +3,7 @@ This module contains all exception classes used by the UiPath Platform SDK. Available exceptions: +- AppNotFoundError: Raised when an Action Center app cannot be found by name - BaseUrlMissingError: Raised when base URL is not configured - SecretMissingError: Raised when access token is not configured - FolderNotFoundException: Raised when a folder cannot be found @@ -16,6 +17,7 @@ - EnrichedException: Enriched HTTP error with detailed request/response information """ +from ._app_not_found_error import AppNotFoundError from ._base_url_missing_error import BaseUrlMissingError from ._batch_transform_failed_exception import BatchTransformFailedException from ._batch_transform_not_complete_exception import BatchTransformNotCompleteException @@ -33,6 +35,7 @@ from .datafabric_error_codes import DataFabricErrorCategory __all__ = [ + "AppNotFoundError", "BaseUrlMissingError", "DataFabricError", "DataFabricErrorCategory", diff --git a/packages/uipath-platform/src/uipath/platform/errors/_app_not_found_error.py b/packages/uipath-platform/src/uipath/platform/errors/_app_not_found_error.py new file mode 100644 index 000000000..0d2d4eff0 --- /dev/null +++ b/packages/uipath-platform/src/uipath/platform/errors/_app_not_found_error.py @@ -0,0 +1,10 @@ +class AppNotFoundError(Exception): + """Raised when an Action Center app cannot be found by name. + + The app is either not deployed in the tenant, or not deployed in the + folder the caller asked for. + """ + + def __init__(self, message: str): + self.message = message + super().__init__(self.message) diff --git a/packages/uipath-platform/src/uipath/platform/resume_triggers/_protocol.py b/packages/uipath-platform/src/uipath/platform/resume_triggers/_protocol.py index c7956287e..d18cd3a2d 100644 --- a/packages/uipath-platform/src/uipath/platform/resume_triggers/_protocol.py +++ b/packages/uipath-platform/src/uipath/platform/resume_triggers/_protocol.py @@ -59,6 +59,7 @@ ) from uipath.platform.documents import DocumentsService, DocumentsServiceV2 from uipath.platform.errors import ( + AppNotFoundError, BatchTransformFailedException, BatchTransformNotCompleteException, ContextGroundingIndexNotFoundError, @@ -694,22 +695,30 @@ async def _handle_task_trigger( resume_trigger.item_key = value.action.key elif isinstance(value, (CreateTask, CreateEscalation)): uipath = UiPath() - action = await uipath.tasks.create_async( - title=value.title, - app_name=value.app_name if value.app_name else "", - app_folder_path=value.app_folder_path or None, - app_folder_key=value.app_folder_key or None, - app_key=value.app_key if value.app_key else "", - assignee=value.assignee if value.assignee else "", - recipient=value.recipient if value.recipient else "", - data=value.data, - priority=value.priority, - labels=value.labels, - is_actionable_message_enabled=value.is_actionable_message_enabled, - actionable_message_metadata=value.actionable_message_metadata, - task_source_metadata=value.task_source_metadata, - source_name=value.source_name, - ) + try: + action = await uipath.tasks.create_async( + title=value.title, + app_name=value.app_name if value.app_name else "", + app_folder_path=value.app_folder_path or None, + app_folder_key=value.app_folder_key or None, + app_key=value.app_key if value.app_key else "", + assignee=value.assignee if value.assignee else "", + recipient=value.recipient if value.recipient else "", + data=value.data, + priority=value.priority, + labels=value.labels, + is_actionable_message_enabled=value.is_actionable_message_enabled, + actionable_message_metadata=value.actionable_message_metadata, + task_source_metadata=value.task_source_metadata, + source_name=value.source_name, + ) + except AppNotFoundError as e: + raise UiPathFaultedTriggerError( + ErrorCategory.DEPLOYMENT, + "Action app not found. Check that the app is deployed and " + "available in the configured folder.", + str(e), + ) from e if not action: raise Exception("Failed to create action") resume_trigger.item_key = action.key diff --git a/packages/uipath-platform/tests/services/test_actions_service.py b/packages/uipath-platform/tests/services/test_actions_service.py index f4505d1bd..a1d798ed0 100644 --- a/packages/uipath-platform/tests/services/test_actions_service.py +++ b/packages/uipath-platform/tests/services/test_actions_service.py @@ -15,6 +15,7 @@ ) from uipath.platform.action_center.tasks import TaskRecipient, TaskRecipientType from uipath.platform.constants import HEADER_USER_AGENT +from uipath.platform.errors import AppNotFoundError @pytest.fixture @@ -633,7 +634,7 @@ def test_create_raises_when_app_not_found_in_tenant( ) with pytest.raises( - Exception, match="'my-app' was not found in the current tenant" + AppNotFoundError, match="'my-app' was not found in the current tenant" ): tasks_service.create(title="Test", app_name="my-app") @@ -658,7 +659,7 @@ def test_create_raises_when_app_not_found_in_folder_path( ) with pytest.raises( - Exception, + AppNotFoundError, match="'my-app' was not found in folder with fully qualified name 'folder-b'", ): tasks_service.create( @@ -686,7 +687,7 @@ def test_create_raises_when_app_not_found_in_folder_key( ) with pytest.raises( - Exception, + AppNotFoundError, match="'my-app' was not found in folder with identifier 'wrong-key'", ): tasks_service.create( diff --git a/packages/uipath-platform/tests/services/test_hitl.py b/packages/uipath-platform/tests/services/test_hitl.py index b87f50c55..923940763 100644 --- a/packages/uipath-platform/tests/services/test_hitl.py +++ b/packages/uipath-platform/tests/services/test_hitl.py @@ -72,7 +72,10 @@ ValidateExtractionAction, ) from uipath.platform.documents.documents import DocumentsApiVersion -from uipath.platform.errors import ContextGroundingIndexNotFoundError +from uipath.platform.errors import ( + AppNotFoundError, + ContextGroundingIndexNotFoundError, +) from uipath.platform.orchestrator import Job, JobErrorInfo from uipath.platform.orchestrator.job import JobState from uipath.platform.resume_triggers import ( @@ -1287,6 +1290,39 @@ async def test_create_resume_trigger_create_task( source_name="Agent", ) + @pytest.mark.anyio + async def test_missing_task_app_is_deployment_error( + self, + setup_test_env: None, + ) -> None: + """A missing Action Center app is the caller's deployment, not a system fault.""" + create_action = CreateTask( + title="Test Action", + app_name="TestApp", + app_folder_path="/test/path", + data={"input": "test-input"}, + ) + missing_app = AppNotFoundError( + "App 'TestApp' was not found in folder with fully qualified name " + "'/test/path'" + ) + + with patch( + "uipath.platform.action_center._tasks_service.TasksService.create_async", + new=AsyncMock(side_effect=missing_app), + ): + with pytest.raises(UiPathFaultedTriggerError) as exc_info: + await UiPathResumeTriggerCreator().create_trigger(create_action) + + error = exc_info.value + assert error.category == ErrorCategory.DEPLOYMENT + assert error.message == ( + "Action app not found. Check that the app is deployed and available in " + "the configured folder." + ) + assert error.detail == str(missing_app) + assert error.__cause__ is missing_app + @pytest.mark.anyio async def test_create_resume_trigger_wait_task( self, diff --git a/packages/uipath-platform/uv.lock b/packages/uipath-platform/uv.lock index 479b3bdca..17d0ca82d 100644 --- a/packages/uipath-platform/uv.lock +++ b/packages/uipath-platform/uv.lock @@ -1082,7 +1082,7 @@ dev = [ [[package]] name = "uipath-platform" -version = "0.3.12" +version = "0.3.13" source = { editable = "." } dependencies = [ { name = "anyio" }, diff --git a/packages/uipath/uv.lock b/packages/uipath/uv.lock index ab608bcd9..ffe400b67 100644 --- a/packages/uipath/uv.lock +++ b/packages/uipath/uv.lock @@ -2883,7 +2883,7 @@ wheels = [ [[package]] name = "uipath-platform" -version = "0.3.12" +version = "0.3.13" source = { editable = "../uipath-platform" } dependencies = [ { name = "anyio" },