Skip to content

Commit 8a3b051

Browse files
committed
fix: Loop node exception handling
1 parent cc0cde9 commit 8a3b051

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

apps/application/flow/step_node/loop_node/impl/base_loop_node.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@
99
import time
1010
from typing import Dict, List
1111

12+
from django.utils.translation import gettext as _
13+
1214
from application.flow.common import Answer
1315
from application.flow.i_step_node import NodeResult, WorkFlowPostHandler, INode
1416
from application.flow.step_node.loop_node.i_loop_node import ILoopNode
1517
from application.flow.tools import Reasoning
1618
from application.models import ChatRecord
1719
from common.handle.impl.response.loop_to_response import LoopToResponse
1820
from maxkb.const import CONFIG
19-
from django.utils.translation import gettext as _
2021

2122
max_loop_count = int((CONFIG.get("MAX_LOOP_COUNT") or 1000))
2223

@@ -173,7 +174,17 @@ def loop(workflow_manage_new_instance, node: INode, generate_loop):
173174
answer += content_chunk
174175
yield chunk
175176
if chunk.get('node_status', "SUCCESS") == 'ERROR':
176-
raise Exception(chunk.get('content'))
177+
insert_or_replace(loop_node_data, index, instance.get_runtime_details())
178+
insert_or_replace(loop_answer_data, index,
179+
get_answer_list(instance, child_node_node_dict, node.runtime_node_id))
180+
node.context['is_interrupt_exec'] = is_interrupt_exec
181+
node.context['loop_node_data'] = loop_node_data
182+
node.context['loop_answer_data'] = loop_answer_data
183+
node.context["index"] = current_index
184+
node.context["item"] = current_index
185+
node.status = 500
186+
node.err_message = chunk.get('content')
187+
return
177188
node_type = chunk.get('node_type')
178189
if node_type == 'form-node':
179190
break_outer = True
@@ -182,7 +193,6 @@ def loop(workflow_manage_new_instance, node: INode, generate_loop):
182193
start_node_data = None
183194
chat_record = None
184195
child_node = None
185-
loop_global_data = instance.context
186196
insert_or_replace(loop_node_data, index, instance.get_runtime_details())
187197
insert_or_replace(loop_answer_data, index,
188198
get_answer_list(instance, child_node_node_dict, node.runtime_node_id))

0 commit comments

Comments
 (0)