Skip to content

Commit 82134a1

Browse files
authored
fix: Replace generic exceptions with specific error classes in task p… (#12036)
Signed-off-by: -LAN- <laipz8200@outlook.com>
1 parent 6a0ff36 commit 82134a1

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

api/core/app/task_pipeline/easy_ui_based_generate_task_pipeline.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def _to_blocking_response(
177177
else:
178178
continue
179179

180-
raise Exception("Queue listening stopped unexpectedly.")
180+
raise RuntimeError("queue listening stopped unexpectedly.")
181181

182182
def _to_stream_response(
183183
self, generator: Generator[StreamResponse, None, None]

api/core/app/task_pipeline/exc.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class TaskPipilineError(ValueError):
2+
pass
3+
4+
5+
class RecordNotFoundError(TaskPipilineError):
6+
def __init__(self, record_name: str, record_id: str):
7+
super().__init__(f"{record_name} with id {record_id} not found")
8+
9+
10+
class WorkflowRunNotFoundError(RecordNotFoundError):
11+
def __init__(self, workflow_run_id: str):
12+
super().__init__("WorkflowRun", workflow_run_id)
13+
14+
15+
class WorkflowNodeExecutionNotFoundError(RecordNotFoundError):
16+
def __init__(self, workflow_node_execution_id: str):
17+
super().__init__("WorkflowNodeExecution", workflow_node_execution_id)

api/core/app/task_pipeline/workflow_cycle_manage.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
WorkflowRunStatus,
5959
)
6060

61+
from .exc import WorkflowNodeExecutionNotFoundError, WorkflowRunNotFoundError
62+
6163

6264
class WorkflowCycleManage:
6365
_application_generate_entity: Union[AdvancedChatAppGenerateEntity, WorkflowAppGenerateEntity]
@@ -898,7 +900,7 @@ def _refetch_workflow_run(self, workflow_run_id: str) -> WorkflowRun:
898900
workflow_run = db.session.query(WorkflowRun).filter(WorkflowRun.id == workflow_run_id).first()
899901

900902
if not workflow_run:
901-
raise Exception(f"Workflow run not found: {workflow_run_id}")
903+
raise WorkflowRunNotFoundError(workflow_run_id)
902904

903905
return workflow_run
904906

@@ -911,6 +913,6 @@ def _refetch_workflow_node_execution(self, node_execution_id: str) -> WorkflowNo
911913
workflow_node_execution = self._wip_workflow_node_executions.get(node_execution_id)
912914

913915
if not workflow_node_execution:
914-
raise Exception(f"Workflow node execution not found: {node_execution_id}")
916+
raise WorkflowNodeExecutionNotFoundError(node_execution_id)
915917

916918
return workflow_node_execution

0 commit comments

Comments
 (0)