Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/uipath-platform/pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 = [
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -33,6 +35,7 @@
from .datafabric_error_codes import DataFabricErrorCategory

__all__ = [
"AppNotFoundError",
"BaseUrlMissingError",
"DataFabricError",
"DataFabricErrorCategory",
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
)
from uipath.platform.documents import DocumentsService, DocumentsServiceV2
from uipath.platform.errors import (
AppNotFoundError,
BatchTransformFailedException,
BatchTransformNotCompleteException,
ContextGroundingIndexNotFoundError,
Expand Down Expand Up @@ -678,7 +679,7 @@
# default to API trigger
return UiPathResumeTriggerName.API

async def _handle_task_trigger(

Check failure on line 682 in packages/uipath-platform/src/uipath/platform/resume_triggers/_protocol.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this function to reduce its Cognitive Complexity from 16 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=UiPath_uipath-python&issues=AaHve8rFzQJZ1Famyqyk&open=AaHve8rFzQJZ1Famyqyk&pullRequest=2002
self, value: Any, resume_trigger: UiPathResumeTrigger
) -> None:
"""Handle task-type resume triggers.
Expand All @@ -694,22 +695,30 @@
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")

Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
38 changes: 37 additions & 1 deletion packages/uipath-platform/tests/services/test_hitl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/uipath-platform/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/uipath/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading