Skip to content

Commit 81a2db6

Browse files
authored
Merge pull request #526 from UiPath/fix/terminal_error_code
fix: display error contract in terminal
2 parents 592d1b8 + 8791d42 commit 81a2db6

3 files changed

Lines changed: 21 additions & 1 deletion

File tree

src/uipath/_cli/_dev/_terminal/__init__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import asyncio
22
import json
3+
import traceback
34
from datetime import datetime
45
from os import environ as env
56
from pathlib import Path
@@ -12,7 +13,9 @@
1213
from textual.widgets import Button, ListView
1314

1415
from ..._runtime._contracts import (
16+
UiPathErrorContract,
1517
UiPathRuntimeContext,
18+
UiPathRuntimeError,
1619
UiPathRuntimeFactory,
1720
)
1821
from ._components._details import RunDetailsPanel
@@ -159,11 +162,23 @@ async def _execute_runtime(self, run: ExecutionRun):
159162
run.status = "completed"
160163
run.end_time = datetime.now()
161164

165+
except UiPathRuntimeError as e:
166+
error_msg = (
167+
f"{e.error_info.code}: {e.error_info.title}\n{e.error_info.detail}"
168+
)
169+
self._add_error_log(run, error_msg)
170+
run.status = "failed"
171+
run.end_time = datetime.now()
172+
run.error = e.error_info
173+
162174
except Exception as e:
163175
error_msg = f"Execution failed: {str(e)}"
164176
self._add_error_log(run, error_msg)
165177
run.status = "failed"
166178
run.end_time = datetime.now()
179+
run.error = UiPathErrorContract(
180+
code="Unknown", title=str(e), detail=traceback.format_exc()
181+
)
167182

168183
self._update_run_in_history(run)
169184
self._update_run_details(run)

src/uipath/_cli/_dev/_terminal/_components/_details.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,10 @@ def _show_run_details(self, run: ExecutionRun):
229229
if hasattr(run, "error") and run.error:
230230
run_details_log.write("[bold red]ERROR:[/bold red]")
231231
run_details_log.write("[dim]" + "=" * 50 + "[/dim]")
232-
run_details_log.write(f"[red]{run.error}[/red]")
232+
if run.error.code:
233+
run_details_log.write(f"[red]Code: {run.error.code}[/red]")
234+
run_details_log.write(f"[red]Title: {run.error.title}[/red]")
235+
run_details_log.write(f"[red]\n{run.error.detail}[/red]")
233236
run_details_log.write("")
234237

235238
# Additional metadata

src/uipath/_cli/_dev/_terminal/_models/_execution.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from typing import List, Optional
44
from uuid import uuid4
55

6+
from ...._runtime._contracts import UiPathErrorContract
67
from ._messages import LogMessage, TraceMessage
78

89

@@ -19,6 +20,7 @@ def __init__(self, entrypoint: str, input_data: str):
1920
self.status = "running" # running, completed, failed
2021
self.traces: List[TraceMessage] = []
2122
self.logs: List[LogMessage] = []
23+
self.error: Optional[UiPathErrorContract] = None
2224

2325
@property
2426
def duration(self) -> str:

0 commit comments

Comments
 (0)