Skip to content

Commit 23f07ac

Browse files
committed
feat(add_error_code): added error code to UiPathLlamaIndexRuntimeError
1 parent 109aff8 commit 23f07ac

4 files changed

Lines changed: 322 additions & 27 deletions

File tree

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "uipath-llamaindex"
3-
version = "0.0.36"
3+
version = "0.0.37"
44
description = "UiPath LlamaIndex SDK"
55
readme = { file = "README.md", content-type = "text/markdown" }
66
requires-python = ">=3.10"
@@ -9,7 +9,7 @@ dependencies = [
99
"llama-index-embeddings-azure-openai>=0.3.8",
1010
"llama-index-llms-azure-openai>=0.3.2",
1111
"openinference-instrumentation-llama-index>=4.3.0",
12-
"uipath>=2.1.54, <2.2.0",
12+
"uipath>=2.1.108, <2.2.0",
1313
]
1414
classifiers = [
1515
"Development Status :: 3 - Alpha",
Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,37 @@
1-
from typing import Optional
1+
from enum import Enum
2+
from typing import Optional, Union
23

3-
from uipath._cli._runtime._contracts import UiPathErrorCategory, UiPathRuntimeError
4+
from uipath._cli._runtime._contracts import (
5+
UiPathBaseRuntimeError,
6+
UiPathErrorCategory,
7+
UiPathErrorCode,
8+
)
49

510

6-
class UiPathLlamaIndexRuntimeError(UiPathRuntimeError):
11+
class LLamaIndexErrorCode(Enum):
12+
AGENT_EXECUTION_FAILURE = "AGENT_EXECUTION_FAILURE"
13+
TIMEOUT_ERROR = "TIMEOUT_ERROR"
14+
SERIALIZE_OUTPUT_ERROR = "SERIALIZE_OUTPUT_ERROR"
15+
16+
CONFIG_MISSING = "CONFIG_MISSING"
17+
CONFIG_INVALID = "CONFIG_INVALID"
18+
19+
WORKFLOW_NOT_FOUND = "WORKFLOW_NOT_FOUND"
20+
WORKFLOW_TYPE_ERROR = "WORKFLOW_TYPE_ERROR"
21+
WORKFLOW_VALUE_ERROR = "WORKFLOW_VALUE_ERROR"
22+
WORKFLOW_LOAD_ERROR = "WORKFLOW_LOAD_ERROR"
23+
WORKFLOW_IMPORT_ERROR = "WORKFLOW_IMPORT_ERROR"
24+
25+
26+
class UiPathLlamaIndexRuntimeError(UiPathBaseRuntimeError):
727
"""Custom exception for LlamaIndex runtime errors with structured error information."""
828

929
def __init__(
1030
self,
11-
code: str,
31+
code: Union[LLamaIndexErrorCode, UiPathErrorCode],
1232
title: str,
1333
detail: str,
1434
category: UiPathErrorCategory = UiPathErrorCategory.UNKNOWN,
1535
status: Optional[int] = None,
1636
):
17-
super().__init__(code, title, detail, category, status, prefix="LlamaIndex")
37+
super().__init__(code.value, title, detail, category, status, prefix="LlamaIndex")

src/uipath_llamaindex/_cli/_runtime/_runtime.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from uipath._cli._runtime._contracts import (
1717
UiPathBaseRuntime,
1818
UiPathErrorCategory,
19+
UiPathErrorCode,
1920
UiPathResumeTrigger,
2021
UiPathRuntimeResult,
2122
UiPathRuntimeStatus,
@@ -24,7 +25,7 @@
2425

2526
from .._utils._config import LlamaIndexConfig
2627
from ._context import UiPathLlamaIndexRuntimeContext
27-
from ._exception import UiPathLlamaIndexRuntimeError
28+
from ._exception import LLamaIndexErrorCode, UiPathLlamaIndexRuntimeError
2829

2930
logger = logging.getLogger(__name__)
3031

@@ -97,7 +98,7 @@ async def execute(self) -> Optional[UiPathRuntimeResult]:
9798
# catch any script exceptions
9899
except Exception as e:
99100
raise UiPathLlamaIndexRuntimeError(
100-
"AGENT_EXECUTION_FAILURE",
101+
LLamaIndexErrorCode.AGENT_EXECUTION_FAILURE,
101102
"There was an exception while executing the agent ",
102103
str(e),
103104
UiPathErrorCategory.USER,
@@ -128,14 +129,14 @@ async def execute(self) -> Optional[UiPathRuntimeResult]:
128129
# check if workflow failed because of timeout constraints
129130
except WorkflowTimeoutError as e:
130131
raise UiPathLlamaIndexRuntimeError(
131-
"TIMEOUT_ERROR",
132+
LLamaIndexErrorCode.TIMEOUT_ERROR,
132133
"Workflow timed out",
133134
str(e),
134135
UiPathErrorCategory.USER,
135136
) from e
136137
except Exception as e:
137138
raise UiPathLlamaIndexRuntimeError(
138-
"SERIALIZE_OUTPUT_ERROR",
139+
LLamaIndexErrorCode.SERIALIZE_OUTPUT_ERROR,
139140
"Failed to serialize output",
140141
str(e),
141142
UiPathErrorCategory.SYSTEM,
@@ -162,7 +163,7 @@ async def execute(self) -> Optional[UiPathRuntimeResult]:
162163
raise
163164
detail = f"Error: {str(e)}"
164165
raise UiPathLlamaIndexRuntimeError(
165-
"EXECUTION_ERROR",
166+
UiPathErrorCode.EXECUTION_ERROR,
166167
"LlamaIndex Runtime execution failed",
167168
detail,
168169
UiPathErrorCategory.USER,
@@ -175,7 +176,7 @@ async def validate(self) -> None:
175176
self.context.input_json = json.loads(self.context.input)
176177
except json.JSONDecodeError as e:
177178
raise UiPathLlamaIndexRuntimeError(
178-
"INPUT_INVALID_JSON",
179+
UiPathErrorCode.INPUT_INVALID_JSON,
179180
"Invalid JSON input",
180181
"The input data is not valid JSON.",
181182
UiPathErrorCategory.USER,
@@ -185,7 +186,7 @@ async def validate(self) -> None:
185186
self.context.config = LlamaIndexConfig()
186187
if not self.context.config.exists:
187188
raise UiPathLlamaIndexRuntimeError(
188-
"CONFIG_MISSING",
189+
LLamaIndexErrorCode.CONFIG_MISSING,
189190
"Invalid configuration",
190191
"Failed to load configuration",
191192
UiPathErrorCategory.DEPLOYMENT,
@@ -195,7 +196,7 @@ async def validate(self) -> None:
195196
self.context.config.load_config()
196197
except Exception as e:
197198
raise UiPathLlamaIndexRuntimeError(
198-
"CONFIG_INVALID",
199+
LLamaIndexErrorCode.CONFIG_INVALID,
199200
"Invalid configuration",
200201
f"Failed to load configuration: {str(e)}",
201202
UiPathErrorCategory.DEPLOYMENT,
@@ -208,7 +209,7 @@ async def validate(self) -> None:
208209
elif not self.context.entrypoint:
209210
workflow_names = ", ".join(w.name for w in workflows)
210211
raise UiPathLlamaIndexRuntimeError(
211-
"ENTRYPOINT_MISSING",
212+
UiPathErrorCode.ENTRYPOINT_MISSING,
212213
"Entrypoint required",
213214
f"Multiple workflows available. Please specify one of: {workflow_names}.",
214215
UiPathErrorCategory.DEPLOYMENT,
@@ -218,7 +219,7 @@ async def validate(self) -> None:
218219
self.workflow_config = self.context.config.get_workflow(self.context.entrypoint)
219220
if not self.workflow_config:
220221
raise UiPathLlamaIndexRuntimeError(
221-
"WORKFLOW_NOT_FOUND",
222+
LLamaIndexErrorCode.WORKFLOW_NOT_FOUND,
222223
"Workflow not found",
223224
f"Workflow '{self.context.entrypoint}' not found.",
224225
UiPathErrorCategory.DEPLOYMENT,
@@ -227,28 +228,28 @@ async def validate(self) -> None:
227228
self.context.workflow = await self.workflow_config.load_workflow()
228229
except ImportError as e:
229230
raise UiPathLlamaIndexRuntimeError(
230-
"WORKFLOW_IMPORT_ERROR",
231+
LLamaIndexErrorCode.WORKFLOW_IMPORT_ERROR,
231232
"Workflow import failed",
232233
f"Failed to import workflow '{self.context.entrypoint}': {str(e)}",
233234
UiPathErrorCategory.USER,
234235
) from e
235236
except TypeError as e:
236237
raise UiPathLlamaIndexRuntimeError(
237-
"WORKFLOW_TYPE_ERROR",
238+
LLamaIndexErrorCode.WORKFLOW_TYPE_ERROR,
238239
"Invalid workflow type",
239240
f"Workflow '{self.context.entrypoint}' is not a valid `Workflow`: {str(e)}",
240241
UiPathErrorCategory.USER,
241242
) from e
242243
except ValueError as e:
243244
raise UiPathLlamaIndexRuntimeError(
244-
"WORKFLOW_VALUE_ERROR",
245+
LLamaIndexErrorCode.WORKFLOW_VALUE_ERROR,
245246
"Invalid workflow value",
246247
f"Invalid value in workflow '{self.context.entrypoint}': {str(e)}",
247248
UiPathErrorCategory.USER,
248249
) from e
249250
except Exception as e:
250251
raise UiPathLlamaIndexRuntimeError(
251-
"WORKFLOW_LOAD_ERROR",
252+
LLamaIndexErrorCode.WORKFLOW_LOAD_ERROR,
252253
"Failed to load workflow",
253254
f"Unexpected error loading workflow '{self.context.entrypoint}': {str(e)}",
254255
UiPathErrorCategory.USER,

0 commit comments

Comments
 (0)